Skip to content

[k2] rpc client API#1635

Open
T-y-c-o-o-n wants to merge 42 commits into
masterfrom
n.siniachenko/k2/rpc-client-boost
Open

[k2] rpc client API#1635
T-y-c-o-o-n wants to merge 42 commits into
masterfrom
n.siniachenko/k2/rpc-client-boost

Conversation

@T-y-c-o-o-n

Copy link
Copy Markdown
Contributor

No description provided.

@T-y-c-o-o-n
T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch from 156e9ec to 222adae Compare June 15, 2026 11:57
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp
Comment thread runtime-light/stdlib/rpc/rpc-queue-functions.h Outdated
Comment thread builtin-functions/kphp-light/stdlib/rpc.txt Outdated
Comment thread runtime-light/k2-platform/k2-header.h
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-header.h
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
Comment thread runtime-light/stdlib/rpc/rpc-api.cpp Outdated
@T-y-c-o-o-n
T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch from a342aa9 to e77636c Compare June 21, 2026 19:19
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-api.h Outdated
Comment thread runtime-light/stdlib/time/util.h Outdated
@T-y-c-o-o-n
T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch 2 times, most recently from 0c1f4cc to 44d348e Compare July 17, 2026 13:14
Comment thread runtime-light/k2-platform/k2-header.h Outdated
Comment thread runtime-light/k2-platform/k2-api.h Outdated
Comment thread runtime-light/stdlib/rpc/rpc-client-state.h Outdated
Comment thread runtime-light/stdlib/rpc/rpc-client-state.h Outdated
Comment thread runtime-light/stdlib/rpc/rpc-query.h
kphp::coro::io_scheduler& m_scheduler{kphp::coro::io_scheduler::get()};
std::chrono::nanoseconds timeout{kphp::time::remaining(deadline)};

co_await m_scheduler.poll(rpc_d, kphp::coro::poll_op::read, timeout);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's possible for timeout to become zero or negative here. Please, read io_scheduler::poll documentation for timeout

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap, handled timeout <= 0 case manually

}
}

kphp::coro::task<void> wait_for_response() noexcept;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's take one more step if you started splitting declarations and definitions:

  1. let's have query_handle's body only include declarations with doc comments
  2. let's have all implementation defined out-of-class

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Only constructors, destructor and assign operators have definition inside class

}
}

std::expected<query_handle, int32_t> send_and_get_handle(std::string_view actor, bool collect_responses_extra_info, bool ignore_answer,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why not just send? Do we really need to highlight that we get handle as a return value?

I don't understand why do we need this function at all. It seems like it's literally part of kphp::rpc::send_request

@T-y-c-o-o-n T-y-c-o-o-n Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Renamed it with send
  • I've moved logic about regularize_extra_headers and collect_response_extra to kphp::rpc::send_request, and leaved here only logic about creating query. That allowed me to avoid rpc_query_handle.cpp file

if (it_rpc_request_handle == rpc_client_instance_st.rpc_query_handles.end()) [[unlikely]] {
co_return request_id;
}
// FIXME after response fetch finished `it_rpc_request_handle` will become invalid iterator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, let's fix this :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WE discussed, that wait_for_response may await inside and overlife object destruction, but this is not a problem, because after wait it does not touch object fields

k2::instant(std::addressof(now_instant));

std::chrono::nanoseconds now_ns{now_instant.time_point_ns};
std::chrono::nanoseconds deadline_ns{duration_cast<std::chrono::nanoseconds>(deadline)};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What is duration_cast here?
  2. It looks like you use duration as time point. Please, correct me if I'm wrong

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'r right. Replaced deadlines types with std::chrono::steady_clock::time_point

@T-y-c-o-o-n T-y-c-o-o-n changed the title [k2] rpc client boost [k2] rpc client API Jul 22, 2026

namespace kphp::rpc {

inline constexpr std::string_view EMPTY_QUERY_ERROR_DESCRIPTION = "fetching rpc response from empty query";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? Isn't it enough to return an error code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

laeved only rpc error code


class query_handle {
k2::descriptor m_descriptor{k2::INVALID_PLATFORM_DESCRIPTOR};
std::chrono::steady_clock::time_point m_deadline{};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for explicit init here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@T-y-c-o-o-n
T-y-c-o-o-n force-pushed the n.siniachenko/k2/rpc-client-boost branch from df743db to 6435238 Compare July 24, 2026 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants