Commit 37f2d7f3 authored by Marc Vef's avatar Marc Vef
Browse files

Improving gkfs_malleability

parent bbedfa37
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -106,9 +106,8 @@ MalleableManager::read_hosts_file() {
    if(hosts.empty()) {
        throw runtime_error(fmt::format("Hostfile empty: '{}'", hostfile));
    }
    GKFS_DATA->spdlogger()->info(
            "{}() Number of hosts for current instance '{}'", __func__,
            hosts.size());
    GKFS_DATA->spdlogger()->info("{}() Number of hosts after expansion '{}'",
                                 __func__, hosts.size());
    return hosts;
}

@@ -209,9 +208,6 @@ MalleableManager::expand_start(int old_server_conf, int new_server_conf) {
    }
    connect_to_hosts(hosts);
    RPC_DATA->distributor()->hosts_size(hosts.size());
    GKFS_DATA->spdlogger()->info(
            "{}() Total number of hosts after expansion: {}", __func__,
            RPC_DATA->distributor()->hosts_size());
    auto abt_err =
            ABT_thread_create(RPC_DATA->io_pool(), expand_abt,
                              ABT_THREAD_ATTR_NULL, nullptr, &redist_thread_);
+89 −19
Original line number Diff line number Diff line
@@ -26,9 +26,10 @@
  SPDX-License-Identifier: GPL-3.0-or-later
*/

#include <fstream>
#include <iostream>
// #include <queue>
#include <string>
#include <utility>

#include <CLI/CLI.hpp>
#include <client/user_functions.hpp>
@@ -37,29 +38,98 @@
using namespace std;

struct cli_options {
    string hosts_file;
    bool verbose = false;
    string action;
    string subcommand;
};

std::pair<int, int>
get_expansion_host_num() {
    // get hosts file and read how much should be expanded
    auto hosts_file_path = std::getenv("LIBGKFS_HOSTS_FILE");
    if(!hosts_file_path) {
        std::cerr
                << "Error: LIBGKFS_HOSTS_FILE environment variable not set.\n";
        return {-1, -1};
    }
    std::ifstream file(hosts_file_path);
    if(!file) {
        std::cerr << "Error: Unable to open file at " << hosts_file_path
                  << ".\n";
        return {-1, -1}; // Indicate an error
    }
    auto initialHostCount = 0;
    auto finalHostCount = 0;
    auto foundSeparator = false;
    std::string line;

    while(std::getline(file, line)) {
        if(line == "#FS_INSTANCE_END") {
            if(foundSeparator) {
                cerr << "marker was found twice. this is not allowed.\n";
                return {-1, -1};
            }
            foundSeparator = true;
            initialHostCount = finalHostCount;
            continue;
        }
        if(!line.empty()) {
            finalHostCount++;
        }
    }
    if(!foundSeparator) {
        initialHostCount = finalHostCount;
    }
    return {initialHostCount, finalHostCount};
}

int
main(int argc, const char* argv[]) {
    CLI::App desc{"Allowed options"};
    cli_options opts{};
    cli_options opts;

    // Global verbose flag
    desc.add_flag("--verbose,-v", opts.verbose, "Verbose output");

    auto expand_args =
            desc.add_subcommand("expand", "Expansion-related actions");
    expand_args->add_option("action", opts.action, "Action to perform")
            ->required()
            ->check(CLI::IsMember({"start", "status", "finalize"}));
    try {
        desc.parse(argc, argv);
    } catch(const CLI::ParseError& e) {
        return desc.exit(e);
    }

    auto err = gkfs_init();
    cout << "Init result " << err << endl;
    if(opts.verbose) { // Check the verbose flag from the main options
        std::cout << "Verbose mode is on." << std::endl;
    }
    int err;
    gkfs_init();

    err = gkfs::malleable::expand_start(1, 2);
    if(opts.action == "start") {
        auto [current_instance, expanded_instance] = get_expansion_host_num();
        if(current_instance == -1 || expanded_instance == -1) {
            return 1;
        }
        err = gkfs::malleable::expand_start(current_instance,
                                            expanded_instance);
        if(err) {
        cout << "Expand start failed. Exiting..." << endl;
            cout << "Expand start failed. Exiting...\n";
            gkfs_end();
            return -1;
        }
    cout << "Expand start " << err << endl;
    err = gkfs::malleable::expand_status();
    cout << "Expand status " << err << endl;
        cout << "Expand start " << err << "\n";
    } else if(opts.action == "status") {
        if(gkfs::malleable::expand_status() > 0) {
            cout << "Expansion in progress...\n";
        } else {
            cout << "No expansion running.\n";
        }
    } else if(opts.action == "finalize") {
        err = gkfs::malleable::expand_finalize();
        cout << "Expand finalize " << err << endl;

    err = gkfs_end();
    cout << "End result " << err << endl;
    }
    gkfs_end();
}
 No newline at end of file