Verified Commit 90612334 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

decr_size RPC now uses Hermes instead of Margo

parent a1444c1e
Loading
Loading
Loading
Loading
+108 −0
Original line number Diff line number Diff line
@@ -550,6 +550,114 @@ struct remove {
    };
};

//==============================================================================
// definitions for decr_size
struct decr_size {

    // forward declarations of public input/output types for this RPC
    class input;
    class output;

    // traits used so that the engine knows what to do with the RPC
    using self_type = decr_size;
    using handle_type = hermes::rpc_handle<self_type>;
    using input_type = input;
    using output_type = output;
    using mercury_input_type = rpc_trunc_in_t;
    using mercury_output_type = rpc_err_out_t;

    // RPC public identifier
    constexpr static const uint64_t public_id = 1291649024;

    // RPC internal Mercury identifier
    constexpr static const hg_id_t mercury_id = public_id;

    // RPC name
    constexpr static const auto name = hg_tag::decr_size;

    // requires response?
    constexpr static const auto requires_response = true;

    // Mercury callback to serialize input arguments
    constexpr static const auto mercury_in_proc_cb = 
        HG_GEN_PROC_NAME(rpc_trunc_in_t);

    // Mercury callback to serialize output arguments
    constexpr static const auto mercury_out_proc_cb = 
        HG_GEN_PROC_NAME(rpc_err_out_t);

    class input {

        template <typename ExecutionContext>
        friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*);

    public:
        input(const std::string& path, uint64_t length) :
            m_path(path),
            m_length(length) { }

        input(input&& rhs) = default;
        input(const input& other) = default;
        input& operator=(input&& rhs) = default;
        input& operator=(const input& other) = default;

        std::string
        path() const {
            return m_path;
        }

        uint64_t
        length() const {
            return m_length;
        }

        explicit
        input(const rpc_trunc_in_t& other) :
            m_path(other.path),
            m_length(other.length) { }

        explicit
        operator rpc_trunc_in_t() {
            return {m_path.c_str(), m_length};
        }

    private:
        std::string m_path;
        uint64_t m_length;
    };

    class output {

        template <typename ExecutionContext>
        friend hg_return_t hermes::detail::post_to_mercury(ExecutionContext*);

    public:
        output() :
            m_err() {}

        output(int32_t err) :
            m_err(err) {}

        output(output&& rhs) = default;
        output(const output& other) = default;
        output& operator=(output&& rhs) = default;
        output& operator=(const output& other) = default;

        explicit 
        output(const rpc_err_out_t& out) {
            m_err = out.err;
        }

        int32_t
        err() const {
            return m_err;
        }

    private:
        int32_t m_err;
    };
};

} // namespace rpc
} // namespace gkfs

+1 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ register_user_request_types() {
    (void) registered_requests().add<gkfs::rpc::create>();
    (void) registered_requests().add<gkfs::rpc::stat>();
    (void) registered_requests().add<gkfs::rpc::remove>();
    (void) registered_requests().add<gkfs::rpc::decr_size>();
}

}} // namespace hermes::detail
+35 −44
Original line number Diff line number Diff line
@@ -76,9 +76,11 @@ int stat(const std::string& path, string& attr) {
        if(out.err() != 0) {
            errno = out.err();
            return -1;
        } else {
            attr = out.db_val();
        }

        attr = out.db_val();
        return 0;

    } catch(const std::exception& ex) {
        CTX->log()->error("{}() while getting rpc output", __func__);
        errno = EBUSY;
@@ -89,51 +91,36 @@ int stat(const std::string& path, string& attr) {
}

int decr_size(const std::string& path, size_t length) {
    hg_handle_t handle;
    rpc_trunc_in_t in{};
    int err = 0;
    in.path = path.c_str();
    in.length = length;

    CTX->log()->debug("{}() Creating Mercury handle ...", __func__);
    auto ret = margo_create_wrap(rpc_decr_size_id, path, handle);
    if (ret != HG_SUCCESS) {
        errno = EBUSY;
        return -1;
    }
    auto endp = CTX->hosts2().at(
        CTX->distributor()->locate_file_metadata(path));

    // Send rpc
    ret = margo_forward_timed_wrap(handle, &in);
    // Get response
    if (ret != HG_SUCCESS) {
        CTX->log()->error("{}() timed out", __func__);
        margo_destroy(handle);
        errno = EBUSY;
    try {

        CTX->log()->debug("{}() Sending RPC ...", __func__);
        // TODO(amiranda): add a post() with RPC_TIMEOUT to hermes so that we can
        // retry for RPC_TRIES (see old commits with margo)
        // TODO(amiranda): hermes will eventually provide a post(endpoint) 
        // returning one result and a broadcast(endpoint_set) returning a 
        // result_set. When that happens we can remove the .at(0) :/
        auto out = 
            ld_network_service->post<gkfs::rpc::decr_size>(
                    endp, path, length).get().at(0);

        CTX->log()->debug("{}() Got response success: {}", __func__, out.err());

        if(out.err() != 0) {
            errno = out.err();
            return -1;
        }

    rpc_err_out_t out{};
    ret = margo_get_output(handle, &out);
    if (ret != HG_SUCCESS) {
        return 0;

    } catch(const std::exception& ex) {
        CTX->log()->error("{}() while getting rpc output", __func__);
        margo_free_output(handle, &out);
        margo_destroy(handle);
        errno = EBUSY;
        return -1;
    }

    CTX->log()->debug("{}() Got response: {}", __func__, out.err);

    if(out.err != 0){
        //In case of error out.err contains the
        //corresponding value of errno
        errno = out.err;
        err = -1;
    }

    margo_free_output(handle, &out);
    margo_destroy(handle);
    return err;
}

int rm_node(const std::string& path, const bool remove_metadentry_only) {
@@ -143,8 +130,8 @@ int rm_node(const std::string& path, const bool remove_metadentry_only) {
    // else, send an rpc to all hosts and thus broadcast chunk_removal.
    if(remove_metadentry_only) {

        auto idx = CTX->distributor()->locate_file_metadata(path);
        auto endp = CTX->hosts2().at(idx);
        auto endp = CTX->hosts2().at(
            CTX->distributor()->locate_file_metadata(path));

        try {

@@ -159,7 +146,12 @@ int rm_node(const std::string& path, const bool remove_metadentry_only) {

            CTX->log()->debug("{}() Got response success: {}", __func__, out.err());

            assert(out.err() == 0);
            if(out.err() != 0) {
                errno = out.err();
                return -1;
            }
            
            return 0;

        } catch(const std::exception& ex) {
            CTX->log()->error("{}() while getting rpc output", __func__);
@@ -170,7 +162,6 @@ int rm_node(const std::string& path, const bool remove_metadentry_only) {
        return 0;
    }


    std::size_t rpc_target_size2 = CTX->hosts2().size();
    std::vector<hermes::rpc_handle<gkfs::rpc::remove>> handles;