Commit 6cf7db27 authored by Marc Vef's avatar Marc Vef
Browse files

Merge branch 'fix_stat' into 'master'



Refactor stat

See merge request zdvresearch_bsc/adafs!55

Signed-off-by: default avatarMarc Vef <vef@uni-mainz.de>
parents c61d0da5 ce28b4b0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ int create_metadentry(const std::string& path, mode_t mode);

int db_val_to_stat(const std::string& path, std::string db_val, struct stat& attr);

int get_metadentry(const std::string& path, std::string& val);

int get_metadentry(const std::string& path, Metadata& md);

int remove_metadentry(const std::string& path);
+10 −2
Original line number Diff line number Diff line
@@ -42,6 +42,14 @@ int create_metadentry(const std::string& path, mode_t mode) {
    return db_put_metadentry(path, md.to_KVentry()) ? 0 : -1;
}

int get_metadentry(const std::string& path, std::string& val) {
    auto ok = db_get_metadentry(path, val);
    if (!ok || val.size() == 0) {
        return -1;
    }
    return 0;
}

/**
 * Returns the metadata of an object at a specific path. The metadata can be of dummy values if configured
 * @param path
@@ -50,8 +58,8 @@ int create_metadentry(const std::string& path, mode_t mode) {
 */
int get_metadentry(const std::string& path, Metadata& md) {
    string val;
    auto err = db_get_metadentry(path, val);
    if (!err || val.size() == 0) {
    auto err = get_metadentry(path, val);
    if (err) {
        return -1;
    }
    Metadata mdi{path, val};
+2 −2
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ using namespace std;

bool db_get_metadentry(const std::string& key, std::string& val) {
    auto db = ADAFS_DATA->rdb();
    auto err = db->Get(ReadOptions(), key, &val).ok();
    auto ok = db->Get(ReadOptions(), key, &val).ok();
    // TODO check what happens if nothing could have been found. Will val be NULL, nullptr, ""?
    // It matters because the client RPC is checking for an empty string to see if get_attr was successful or not
    return err;
    return ok;
}

bool db_put_metadentry(const std::string& key, const std::string& val) {
+8 −7
Original line number Diff line number Diff line
@@ -4,8 +4,6 @@

#include <daemon/adafs_ops/metadentry.hpp>

#include <daemon/db/db_ops.hpp>

using namespace std;

static hg_return_t rpc_minimal(hg_handle_t handle) {
@@ -97,14 +95,17 @@ static hg_return_t rpc_srv_stat(hg_handle_t handle) {
    ADAFS_DATA->spdlogger()->debug("Got srv stat RPC for path {}", in.path);
    // get the metadata
    string val;
    auto err = db_get_metadentry(in.path, val);
    // TODO set return values proper with errorcodes the whole way
    auto err = get_metadentry(in.path, val);
    if (err) {
        // DB operations failed
        if(val.size() == 0){
            out.err = ENOENT;
        } else {
            out.err = EBUSY;
        }
    } else {
        out.err = 0;
        out.db_val = val.c_str();
    } else {
        // if db_get_metadentry didn't return anything we set the errno to ENOENT
        out.err = ENOENT;
    }

    ADAFS_DATA->spdlogger()->debug("Sending output mode {}", out.db_val);
+25 −21
Original line number Diff line number Diff line
@@ -127,7 +127,7 @@ int rpc_send_stat(const std::string& path, string& attr) {
    hg_handle_t handle;
    rpc_path_only_in_t in{};
    rpc_stat_out_t out{};
    int err = EUNKNOWN;
    int err = 0;
    // fill in
    in.path = path.c_str();
    ld_logger->debug("{}() Creating Mercury handle ...", __func__);
@@ -143,29 +143,33 @@ int rpc_send_stat(const std::string& path, string& attr) {
    ret = margo_forward_timed_wrap(handle, &in);
#endif
    // Get response
    if (ret == HG_SUCCESS) {
        ld_logger->trace("{}() Waiting for response", __func__);
    if (ret != HG_SUCCESS) {
        errno = EBUSY;
        ld_logger->warn("{}() timed out");
        margo_destroy(handle);
        return -1;
    }

    ret = margo_get_output(handle, &out);
        if (ret == HG_SUCCESS) {
    if (ret != HG_SUCCESS) {
        ld_logger->error("{}() while getting rpc output", __func__);
        errno = EBUSY;
        margo_free_output(handle, &out);
        margo_destroy(handle);
        return -1;
    }

    ld_logger->debug("{}() Got response success: {}", __func__, out.err);
            if (out.err == 0) {
                err = 0;
                attr = out.db_val;
            } else {

    if(out.err != 0) {
        err = -1;
        errno = out.err;
            }
    } else {
            // something is wrong
            errno = EBUSY;
            ld_logger->error("{}() while getting rpc output", __func__);
        attr = out.db_val;
    }

    /* clean up resources consumed by this rpc */
    margo_free_output(handle, &out);
    } else {
        ld_logger->warn("{}() timed out");
        errno = EBUSY;
    }
    margo_destroy(handle);
    return err;
}
Loading