Loading include/global/random_slicing/Disk.hpp +7 −7 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public: * @param hostname TODO(dauer) * @param uri TODO(dauer) */ Disk(int64_t id, int64_t capacity, std::string hostname, std::string uri); Disk(uint64_t id, uint64_t capacity, std::string hostname, std::string uri); /** * copy constructor Loading @@ -61,7 +61,7 @@ public: * * @return ID of the disk. Has to be unique all over this library. */ int64_t uint64_t getId() const; /** Loading @@ -70,7 +70,7 @@ public: * @param id ID of the disk. Has to be unique all over this library. */ void setId(int64_t id); setId(uint64_t id); /** * Get the Capacity of the Disk in bytes. (This can also be in any Loading @@ -80,7 +80,7 @@ public: * other scale, but has to be same for ExtentSize of * Distributor) */ int64_t uint64_t getCapacity() const; /** Loading @@ -92,7 +92,7 @@ public: * Distributor) */ void setCapacity(int64_t capacity); setCapacity(uint64_t capacity); /** */ Loading Loading @@ -121,13 +121,13 @@ private: /** * ID of the disk. Has to be unique all over this library. */ int64_t id; uint64_t id; /** * Capacity of the Disk in bytes. (This can also be in any other * scale, but has to be same for ExtentSize of Distributor) */ int64_t capacity; uint64_t capacity; /** * String to be used by developer instantiating this disk. May not be Loading include/global/random_slicing/DistRandSlice.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public: * TODO(dauer): Decide & document freeing of memory */ void removeDisks(std::vector<int64_t> disk_ids); removeDisks(std::vector<uint64_t> disk_ids); /** * @see Distributor::getDisks Loading src/daemon/relocation/config_manager.cpp +74 −34 Original line number Diff line number Diff line Loading @@ -23,10 +23,12 @@ #include <global/rpc/rpc_types.hpp> #include <global/rpc/distributor.hpp> #include <algorithm> #include <cassert> #include <filesystem> #include <iostream> #include <list> #include <set> #include <fmt/format.h> Loading @@ -43,13 +45,9 @@ void calculate_random_slicing() { using gkfs::rpc::host_t; auto hosts = read_hosts_file(); // use id only for new configurations! auto hostsfile_hosts = read_hosts_file(); list<VDRIVE::Disk*> disks; for(const auto& [id, host] : hosts) { const auto& [hostname, uri] = host; disks.emplace_back(new VDRIVE::Disk(id, 1, hostname, uri)); cout << uri << "\n"; } auto filename = GKFS_DATA->hosts_file() + ".rsconfig"; auto dist = std::make_shared<VDRIVE::DistRandSlice>(); if(std::filesystem::exists(filename)) { Loading @@ -65,40 +63,82 @@ calculate_random_slicing() { gkfs::rpc::RandomSlicingDistributor rsdist(dist); // get vector of all existing rs hosts auto all_rs_hosts = rsdist.locate_directory_metadata(""); vector<host_t> all_hostsfile_hosts{}; for(const auto& host : hosts) { all_hostsfile_hosts.push_back(host.first); auto rs_hosts = rsdist.get_hosts_map(); uint64_t max_host_id = 0; std::set<std::string> rs_uris{}; for(const auto& [id, host] : rs_hosts) { max_host_id = std::max(max_host_id, id); rs_uris.insert(host.second); } std::vector<std::string> gone_uris{}; std::vector<uint64_t> gone_ids{}; std::map<std::string, std::string> new_uris_hostname{}; std::set<std::string> hostsfile_uris{}; std::string new_uris_str{}; std::string gone_uris_str{}; for(const auto& [dont_care, host] : hostsfile_hosts) { const auto& [hostname, uri] = host; hostsfile_uris.insert(uri); if(rs_uris.count(uri) == 0) { new_uris_hostname[uri] = hostname; new_uris_str += "\n" + uri; } } // compare with read hosts vector<host_t> gone_hosts{}; vector<host_t> new_hosts{}; for(const auto& [id, host] : rs_hosts) { const auto& [hostname, uri] = host; if(hostsfile_uris.count(uri) == 0) { gone_uris.push_back(uri); gone_ids.push_back(id); gone_uris_str += "\n" + uri; } } // lists need to be sorted for set_difference std::sort(all_rs_hosts.begin(), all_rs_hosts.end()); std::sort(all_hostsfile_hosts.begin(), all_hostsfile_hosts.end()); GKFS_DATA->spdlogger()->info("Hosts to be added: {}", new_uris_str); GKFS_DATA->spdlogger()->info("Hosts to be removed: {}", gone_uris_str); /* // gone = rs_hosts \ hostsfile_hosts std::set_difference(all_rs_hosts.begin(), all_rs_hosts.end(), all_hostsfile_hosts.begin(), all_hostsfile_hosts.end(), std::inserter(gone_hosts, gone_hosts.begin())); std::inserter(gone_uris, gone_uris.begin())); // new = hostsfile_hosts \ rs_hosts std::set_difference(all_hostsfile_hosts.begin(), all_hostsfile_hosts.end(), all_rs_hosts.begin(), all_rs_hosts.end(), std::inserter(new_hosts, new_hosts.begin())); all_hostsfile_hosts.end(), all_rs_hosts.begin(), all_rs_hosts.end(), std::inserter(new_uris, new_uris.begin())); */ // remove gone hosts if(gone_ids.size() > 0) { dist->removeDisks(gone_ids); } if(new_uris_hostname.size() > 0) { // add new hosts // write to file // be done with it for(const auto& [uri, hostname] : new_uris_hostname) { disks.emplace_back( new VDRIVE::Disk(++max_host_id, 1, hostname, uri)); } dist->addDisks(&disks); } } else { GKFS_DATA->spdlogger()->info( "No existing random slicing configuration found, " "creating from scratch with {} hosts.", hosts.size()); hostsfile_hosts.size()); for(const auto& [id, host] : hostsfile_hosts) { const auto& [hostname, uri] = host; disks.emplace_back(new VDRIVE::Disk(id, 1, hostname, uri)); cout << uri << "\n"; } dist->setConfiguration(&disks, 1, 1); } for(auto disk : disks) { Loading @@ -110,7 +150,7 @@ calculate_random_slicing() { // Just test reading here VDRIVE::DistRandSlice dist_read{}; dist_read.from_file(filename); dist_read.to_file(filename + ".reexport"); dist_read.to_file(filename + ".debug-reexport"); } unordered_map<uint64_t, pair<string, string>> Loading src/global/random_slicing/Disk.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ using namespace VDRIVE; using namespace std; Disk::Disk(int64_t id, int64_t capacity, std::string hostname, Disk::Disk(uint64_t id, uint64_t capacity, std::string hostname, std::string uri) { this->id = id; this->capacity = capacity; Loading Loading @@ -81,22 +81,22 @@ Disk::setUri(std::string uri) { this->uri = uri; } int64_t uint64_t Disk::getId() const { return this->id; } void Disk::setId(int64_t id) { Disk::setId(uint64_t id) { this->id = id; } int64_t uint64_t Disk::getCapacity() const { return this->capacity; } void Disk::setCapacity(int64_t capacity) { Disk::setCapacity(uint64_t capacity) { this->capacity = capacity; } src/global/random_slicing/DistRandSlice.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ DistRandSlice::addDisks(std::list<Disk*>* disks) { // Added for GekkoFS void DistRandSlice::removeDisks(std::vector<int64_t> disk_ids) { DistRandSlice::removeDisks(std::vector<uint64_t> disk_ids) { // part id -> num blocks to remove std::unordered_map<uint64_t, uint64_t> old_partitions; for(const auto partition : *m_partitions) { Loading Loading
include/global/random_slicing/Disk.hpp +7 −7 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public: * @param hostname TODO(dauer) * @param uri TODO(dauer) */ Disk(int64_t id, int64_t capacity, std::string hostname, std::string uri); Disk(uint64_t id, uint64_t capacity, std::string hostname, std::string uri); /** * copy constructor Loading @@ -61,7 +61,7 @@ public: * * @return ID of the disk. Has to be unique all over this library. */ int64_t uint64_t getId() const; /** Loading @@ -70,7 +70,7 @@ public: * @param id ID of the disk. Has to be unique all over this library. */ void setId(int64_t id); setId(uint64_t id); /** * Get the Capacity of the Disk in bytes. (This can also be in any Loading @@ -80,7 +80,7 @@ public: * other scale, but has to be same for ExtentSize of * Distributor) */ int64_t uint64_t getCapacity() const; /** Loading @@ -92,7 +92,7 @@ public: * Distributor) */ void setCapacity(int64_t capacity); setCapacity(uint64_t capacity); /** */ Loading Loading @@ -121,13 +121,13 @@ private: /** * ID of the disk. Has to be unique all over this library. */ int64_t id; uint64_t id; /** * Capacity of the Disk in bytes. (This can also be in any other * scale, but has to be same for ExtentSize of Distributor) */ int64_t capacity; uint64_t capacity; /** * String to be used by developer instantiating this disk. May not be Loading
include/global/random_slicing/DistRandSlice.hpp +1 −1 Original line number Diff line number Diff line Loading @@ -112,7 +112,7 @@ public: * TODO(dauer): Decide & document freeing of memory */ void removeDisks(std::vector<int64_t> disk_ids); removeDisks(std::vector<uint64_t> disk_ids); /** * @see Distributor::getDisks Loading
src/daemon/relocation/config_manager.cpp +74 −34 Original line number Diff line number Diff line Loading @@ -23,10 +23,12 @@ #include <global/rpc/rpc_types.hpp> #include <global/rpc/distributor.hpp> #include <algorithm> #include <cassert> #include <filesystem> #include <iostream> #include <list> #include <set> #include <fmt/format.h> Loading @@ -43,13 +45,9 @@ void calculate_random_slicing() { using gkfs::rpc::host_t; auto hosts = read_hosts_file(); // use id only for new configurations! auto hostsfile_hosts = read_hosts_file(); list<VDRIVE::Disk*> disks; for(const auto& [id, host] : hosts) { const auto& [hostname, uri] = host; disks.emplace_back(new VDRIVE::Disk(id, 1, hostname, uri)); cout << uri << "\n"; } auto filename = GKFS_DATA->hosts_file() + ".rsconfig"; auto dist = std::make_shared<VDRIVE::DistRandSlice>(); if(std::filesystem::exists(filename)) { Loading @@ -65,40 +63,82 @@ calculate_random_slicing() { gkfs::rpc::RandomSlicingDistributor rsdist(dist); // get vector of all existing rs hosts auto all_rs_hosts = rsdist.locate_directory_metadata(""); vector<host_t> all_hostsfile_hosts{}; for(const auto& host : hosts) { all_hostsfile_hosts.push_back(host.first); auto rs_hosts = rsdist.get_hosts_map(); uint64_t max_host_id = 0; std::set<std::string> rs_uris{}; for(const auto& [id, host] : rs_hosts) { max_host_id = std::max(max_host_id, id); rs_uris.insert(host.second); } std::vector<std::string> gone_uris{}; std::vector<uint64_t> gone_ids{}; std::map<std::string, std::string> new_uris_hostname{}; std::set<std::string> hostsfile_uris{}; std::string new_uris_str{}; std::string gone_uris_str{}; for(const auto& [dont_care, host] : hostsfile_hosts) { const auto& [hostname, uri] = host; hostsfile_uris.insert(uri); if(rs_uris.count(uri) == 0) { new_uris_hostname[uri] = hostname; new_uris_str += "\n" + uri; } } // compare with read hosts vector<host_t> gone_hosts{}; vector<host_t> new_hosts{}; for(const auto& [id, host] : rs_hosts) { const auto& [hostname, uri] = host; if(hostsfile_uris.count(uri) == 0) { gone_uris.push_back(uri); gone_ids.push_back(id); gone_uris_str += "\n" + uri; } } // lists need to be sorted for set_difference std::sort(all_rs_hosts.begin(), all_rs_hosts.end()); std::sort(all_hostsfile_hosts.begin(), all_hostsfile_hosts.end()); GKFS_DATA->spdlogger()->info("Hosts to be added: {}", new_uris_str); GKFS_DATA->spdlogger()->info("Hosts to be removed: {}", gone_uris_str); /* // gone = rs_hosts \ hostsfile_hosts std::set_difference(all_rs_hosts.begin(), all_rs_hosts.end(), all_hostsfile_hosts.begin(), all_hostsfile_hosts.end(), std::inserter(gone_hosts, gone_hosts.begin())); std::inserter(gone_uris, gone_uris.begin())); // new = hostsfile_hosts \ rs_hosts std::set_difference(all_hostsfile_hosts.begin(), all_hostsfile_hosts.end(), all_rs_hosts.begin(), all_rs_hosts.end(), std::inserter(new_hosts, new_hosts.begin())); all_hostsfile_hosts.end(), all_rs_hosts.begin(), all_rs_hosts.end(), std::inserter(new_uris, new_uris.begin())); */ // remove gone hosts if(gone_ids.size() > 0) { dist->removeDisks(gone_ids); } if(new_uris_hostname.size() > 0) { // add new hosts // write to file // be done with it for(const auto& [uri, hostname] : new_uris_hostname) { disks.emplace_back( new VDRIVE::Disk(++max_host_id, 1, hostname, uri)); } dist->addDisks(&disks); } } else { GKFS_DATA->spdlogger()->info( "No existing random slicing configuration found, " "creating from scratch with {} hosts.", hosts.size()); hostsfile_hosts.size()); for(const auto& [id, host] : hostsfile_hosts) { const auto& [hostname, uri] = host; disks.emplace_back(new VDRIVE::Disk(id, 1, hostname, uri)); cout << uri << "\n"; } dist->setConfiguration(&disks, 1, 1); } for(auto disk : disks) { Loading @@ -110,7 +150,7 @@ calculate_random_slicing() { // Just test reading here VDRIVE::DistRandSlice dist_read{}; dist_read.from_file(filename); dist_read.to_file(filename + ".reexport"); dist_read.to_file(filename + ".debug-reexport"); } unordered_map<uint64_t, pair<string, string>> Loading
src/global/random_slicing/Disk.cpp +5 −5 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ using namespace VDRIVE; using namespace std; Disk::Disk(int64_t id, int64_t capacity, std::string hostname, Disk::Disk(uint64_t id, uint64_t capacity, std::string hostname, std::string uri) { this->id = id; this->capacity = capacity; Loading Loading @@ -81,22 +81,22 @@ Disk::setUri(std::string uri) { this->uri = uri; } int64_t uint64_t Disk::getId() const { return this->id; } void Disk::setId(int64_t id) { Disk::setId(uint64_t id) { this->id = id; } int64_t uint64_t Disk::getCapacity() const { return this->capacity; } void Disk::setCapacity(int64_t capacity) { Disk::setCapacity(uint64_t capacity) { this->capacity = capacity; }
src/global/random_slicing/DistRandSlice.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ DistRandSlice::addDisks(std::list<Disk*>* disks) { // Added for GekkoFS void DistRandSlice::removeDisks(std::vector<int64_t> disk_ids) { DistRandSlice::removeDisks(std::vector<uint64_t> disk_ids) { // part id -> num blocks to remove std::unordered_map<uint64_t, uint64_t> old_partitions; for(const auto partition : *m_partitions) { Loading