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

stat RPC now uses Hermes instead of Margo

parent 9d8bdb91
Loading
Loading
Loading
Loading
+109 −0
Original line number Diff line number Diff line
@@ -331,6 +331,115 @@ struct create {
    };
};

//==============================================================================
// definitions for stat
struct stat {

    // 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 = stat;
    using handle_type = hermes::rpc_handle<self_type>;
    using input_type = input;
    using output_type = output;
    using mercury_input_type = rpc_path_only_in_t;
    using mercury_output_type = rpc_stat_out_t;

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

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

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

    // 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_path_only_in_t);

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

    class input {

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

    public:
        input(const std::string& path ) :
            m_path(path) { }

        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;
        }

        explicit
        input(const rpc_path_only_in_t& other) :
            m_path(other.path) { }

        explicit
        operator rpc_path_only_in_t() {
            return {m_path.c_str()};
        }

    private:
        std::string m_path;
    };

    class output {

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

    public:
        output() :
            m_err(),
            m_db_val() {}

        output(int32_t err, const std::string& db_val) :
            m_err(err),
            m_db_val(db_val) {}

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

        explicit 
        output(const rpc_stat_out_t& out) {
            m_err = out.err;
            m_db_val = out.db_val;
        }

        int32_t
        err() const {
            return m_err;
        }

        std::string
        db_val() const {
            return m_db_val;
        }

    private:
        int32_t m_err;
        std::string m_db_val;
    };
};

} // namespace rpc
} // namespace gkfs

+1 −0
Original line number Diff line number Diff line
@@ -192,6 +192,7 @@ bool init_hermes_client(const std::string& transport_prefix) {

    rpc_config_id = gkfs::rpc::fs_config::public_id;
    rpc_mk_node_id = gkfs::rpc::create::public_id;
    rpc_stat_id = gkfs::rpc::stat::public_id;

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

}} // namespace hermes::detail
+22 −38
Original line number Diff line number Diff line
@@ -58,50 +58,34 @@ int mk_node(const std::string& path, const mode_t mode) {
}

int stat(const std::string& path, string& attr) {
    hg_handle_t handle;
    rpc_path_only_in_t in{};
    rpc_stat_out_t out{};
    int err = 0;
    // fill in
    in.path = path.c_str();
    CTX->log()->debug("{}() Creating Mercury handle ...", __func__);
    auto ret = margo_create_wrap(rpc_stat_id, path, handle);
    if (ret != HG_SUCCESS) {
        errno = EBUSY;
        return -1;
    }
    // Send rpc
    ret = margo_forward_timed_wrap(handle, &in);
    // Get response
    if (ret != HG_SUCCESS) {
        errno = EBUSY;
        CTX->log()->error("{}() timed out", __func__);
        margo_destroy(handle);

    auto endp = CTX->hosts2().at(
            CTX->distributor()->locate_file_metadata(path));
    
    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::stat>(endp, path).get().at(0);
        CTX->log()->debug("{}() Got response success: {}", __func__, out.err());

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

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

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

    if(out.err != 0) {
        err = -1;
        errno = out.err;
    } else {
        attr = out.db_val;
    }

    /* clean up resources consumed by this rpc */
    margo_free_output(handle, &out);
    margo_destroy(handle);
    return err;
    return 0;
}

int decr_size(const std::string& path, size_t length) {