Commit 368bbd09 authored by David Auer's avatar David Auer
Browse files

Store hostname and uri in random slicing configuration

parent 5ab0ebad
Loading
Loading
Loading
Loading
+29 −44
Original line number Diff line number Diff line
@@ -27,16 +27,16 @@ namespace VDRIVE {
class Disk {
public:
    /**
     * instantiates a new Disk with the given values.
     * Instantiates a new Disk with the given values.
     *
     * @param id ID of the disk. Has to be unique all over this library.
     * @param capacity Capacity of the Disk in bytes. (This can also be in
     *                 any other scale, but has to be same for ExtentSize
     *                 of Distributor)
     * @param data Pointer to be used by developer instantiating this disk.
     *             May not be changed by Distributors!
     * @param hostname TODO(dauer)
     * @param uri TODO(dauer)
     */
    Disk(int64_t id, int64_t capacity, void* data);
    Disk(int64_t id, int64_t capacity, std::string hostname, std::string uri);

    /**
     * copy constructor
@@ -45,6 +45,12 @@ public:
     */
    Disk(const Disk& orig);

    /**
     * Instantiates a new Disk with values read from the given ifstream.
     * This is assumed to be written previously by Disk::serialize().
     */
    Disk(std::ifstream& in);

    /**
     * Destructor
     */
@@ -89,54 +95,27 @@ public:
    setCapacity(int64_t capacity);

    /**
     * Get the Pointer to be used by developer instantiating this disk.
     * May not be changed by Distributors!
     *
     * @return Pointer to be used by developer instantiating this disk.
     *         May not be changed by Distributors!
     */
    void*
    getData() const;
    std::string
    getHostname() const;

    /**
     * Set the Pointer to be used by developer instantiating this disk. May not
     * be changed by Distributors!
     * May not be changed by Distributors!
     *
     * @param data Pointer to be used by developer instantiating this disk.
     * @param hostname to be used by developer instantiating this disk.
     *             May not be changed by Distributors!
     */
    void
    setData(void* data);
    setHostname(std::string data);

    /**
     * Get the Root-Type of XML-Elements representing this class.
     *
     * @return the Root-Type of XML-Elements representing this class.
     */
    static std::string
    getXMLRootType() {
        return std::string("Disk");
    }
    std::string
    getUri() const;

    /**
     * Using this method it is possible to store a list of disks in a file.
     *
     * @param disks The disks to be stored
     * @param filename The name of the file the disks shall be stored in.
     */
    static void
    storeDiskList(std::list<Disk*>* disks, std::string filename);
    void
    setUri(std::string uri);

    /**
     * Using this method it is possible to read a list of disks out of a
     * file.
     *
     * @param filename The name of the file containing the disks.
     *
     * @return A list with the disks readen out of the file.
     */
    static std::list<Disk*>*
    loadDiskList(std::string filename);
    void
    serialize(std::ofstream& out);

private:
    /**
@@ -151,10 +130,16 @@ private:
    int64_t capacity;

    /**
     * Pointer to be used by developer instantiating this disk. May not be
     * String to be used by developer instantiating this disk. May not be
     * changed by Distributors!
     */
    std::string hostname;

    /**
     * String to be used by developer instantiating this disk. May not be
     * changed by Distributors!
     */
    void* data;
    std::string uri;
};
} // namespace VDRIVE
#endif /* _DISK_H */
+10 −4
Original line number Diff line number Diff line
@@ -461,12 +461,18 @@ parse_input(const po::variables_map& vm) {


    if(gkfs::config::dynamic_placement && vm.count("start-relocation")) {
        cout << "Starting relocation...\n";

        std::cout << "Starting relocation...\n";
        try {
            // TODO just testing at the moment
            gkfs::relocation::calculate_random_slicing();

            gkfs::relocation::do_relocation();
        } catch(std::exception& e) {

            cerr << fmt::format("Error during start-relocation: '{}'. Exiting.",
                                e.what());
            exit(EXIT_FAILURE);
        }
        // Don't create any directories and no interest in the other options
        exit(0);
    }
+9 −2
Original line number Diff line number Diff line
@@ -47,7 +47,8 @@ calculate_random_slicing() {
    for(const auto& host : hosts) {
        auto first = host.first;
        auto second = host.second;
        disks.emplace_back(new VDRIVE::Disk(++id, 1, nullptr /*host.second*/));
        disks.emplace_back(new VDRIVE::Disk(++id, 1, host.first,
                                            host.second)); // std::move?
        cout << second << "\n";
    }
    // Add Disks
@@ -56,7 +57,13 @@ calculate_random_slicing() {
        delete disk;
    }

    dist.to_file(GKFS_DATA->hosts_file() + ".rsconfig");
    auto filename = GKFS_DATA->hosts_file() + ".rsconfig";
    dist.to_file(filename);

    // Just test reading here
    VDRIVE::DistRandSlice dist_read(true, true);
    dist_read.from_file(filename);
    dist_read.to_file(filename + ".reexport");
}

vector<pair<string, string>>
+52 −11
Original line number Diff line number Diff line
@@ -6,38 +6,79 @@
 * Created on 20. Januar 2010, 10:39
 */

#include <cassert>
#include <fstream>
#include <string>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <vector>

#include <global/random_slicing/Disk.hpp>

using namespace VDRIVE;
using namespace std;

Disk::Disk(int64_t id, int64_t capacity, void* data) {
Disk::Disk(int64_t id, int64_t capacity, std::string hostname,
           std::string uri) {
    this->id = id;
    this->capacity = capacity;
    this->data = data;
    this->hostname = hostname;
    this->uri = uri;
}

Disk::Disk(const Disk& orig) {
    this->id = orig.id;
    this->capacity = orig.capacity;
    this->data = orig.data;
    this->hostname = orig.hostname;
    this->uri = orig.uri;
}

Disk::Disk(std::ifstream& in) {
    size_t str_len;
    in >> this->id >> this->capacity >> str_len;

    // read hostname
    std::vector<char> buf(str_len);
    char whitespace;
    in.read(&whitespace, 1); // read whitespace
    assert(whitespace == ' ');
    in.read(&buf[0], str_len);
    this->hostname = std::string(&buf[0], &buf[str_len]);

    // read uri
    in >> str_len;
    buf.resize(str_len);
    in.read(&whitespace, 1); // read whitespace
    assert(whitespace == ' ');
    in.read(&buf[0], str_len);
    this->uri = std::string(&buf[0], &buf[str_len]);
}

void
Disk::serialize(std::ofstream& out) {
    out << this->id << " " << this->capacity << " " << this->hostname.size()
        << " " << this->hostname << " " << this->uri.size() << " " << this->uri
        << "\n";
}

Disk::~Disk() {}

void*
Disk::getData() const {
    return this->data;
std::string
Disk::getHostname() const {
    return this->hostname;
}

void
Disk::setHostname(std::string hostname) {
    this->hostname = hostname;
}

std::string
Disk::getUri() const {
    return this->uri;
}

void
Disk::setData(void* data) {
    this->data = data;
Disk::setUri(std::string uri) {
    this->uri = uri;
}

int64_t
+23 −19
Original line number Diff line number Diff line
@@ -1167,7 +1167,7 @@ DistRandSlice::compute_interval_sizes(void) {

void
DistRandSlice::from_file(std::string filename) {
    ifstream in;
    std::ifstream in;
    in.open(filename);
    cleanup();

@@ -1175,10 +1175,8 @@ DistRandSlice::from_file(std::string filename) {
    in >> m_num_disks;
    m_disks = new std::unordered_map<uint64_t, Disk*>();
    for(uint64_t i = 0; i < m_num_disks; i++) {
        int64_t id;
        int64_t capacity;
        in >> id >> capacity;
        (*m_disks)[id] = new Disk(id, capacity, nullptr);
        Disk* disk = new Disk(in);
        (*m_disks)[disk->getId()] = disk;
    }

    in >> m_num_partitions;
@@ -1197,33 +1195,39 @@ DistRandSlice::from_file(std::string filename) {
    m_interval_tree =
            new flat_segment_tree(VSPACE_MIN, VSPACE_MAX, m_tree_init_value);

    uint64_t last_low_key;
    uint64_t last_value;
    uint64_t next_low_key;
    uint64_t prev_low_key;
    uint64_t prev_value;
    // next low key is needed as previous high key
    uint64_t next_low_prev_high_key;
    uint64_t next_value;
    in >> last_low_key >> last_value;
    for(uint64_t i = 0; i < num_intervals - 1; i++) {
        in >> next_low_key >> next_value;
        m_interval_tree->insert_back(last_low_key, next_low_key, last_value);
        last_low_key = next_low_key;
        last_value = next_value;
    }
    m_interval_tree->insert_back(last_low_key, VSPACE_MAX, last_value);
    // read one entry in advance to get the high key
    in >> prev_low_key >> prev_value;
    for(uint64_t i = 0; i < num_intervals; i++) {
        // on last interval, use VSPACE_MAX as high key and skip reading
        if(num_intervals == i + 1) {
            next_low_prev_high_key = VSPACE_MAX;
        } else {
            in >> next_low_prev_high_key >> next_value;
        }
        m_interval_tree->insert_back(prev_low_key, next_low_prev_high_key,
                                     prev_value);
        prev_low_key = next_low_prev_high_key;
        prev_value = next_value;
    }
    // m_interval_tree->insert_back(prev_low_key, VSPACE_MAX, prev_value);
    m_interval_tree->build_tree();
    assert(m_interval_tree->is_tree_valid());
}

void
DistRandSlice::to_file(std::string filename) {
    ofstream out;
    std::ofstream out;
    out.open(filename);
    // auto &out = cout;
    assert(m_copies == 1); // other m_copies are not fully implemented
    out << m_num_disks << "\n";
    for(auto& pair : *m_disks) {
        Disk* disk = pair.second;
        out << disk->getId() << " " << disk->getCapacity() << "\n";
        assert(disk->getData() == nullptr);
        disk->serialize(out);
    }

    out << "\n\n" << m_num_partitions << "\n";