Skip to content

Commit

Permalink
implement shutdown request handling in endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
t-horikawa committed Apr 22, 2024
1 parent be7bcb7 commit c10849e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/tateyama/endpoint/common/worker_common.h
Expand Up @@ -249,6 +249,35 @@ class worker_common {
return true;
}

case tateyama::proto::endpoint::request::Request::kShutdown:
{
VLOG_LP(log_trace) << "received shutdown request, slot = " << slot; //NOLINT
{
tateyama::session::shutdown_request_type shutdown_type{};
switch (rq.shutdown().type()) {
case tateyama::proto::endpoint::request::ShutdownType::SHUTDOWN_TYPE_NOT_SET:
shutdown_type = tateyama::session::shutdown_request_type::forceful;
break;
case tateyama::proto::endpoint::request::ShutdownType::GRACEFUL:
shutdown_type = tateyama::session::shutdown_request_type::graceful;
break;
case tateyama::proto::endpoint::request::ShutdownType::FORCEFUL:
shutdown_type = tateyama::session::shutdown_request_type::forceful;
break;
default: // error
return false;
}
request_shutdown(shutdown_type);

// FIXME confirm when response should be sent
tateyama::proto::endpoint::response::Shutdown rp{};
auto body = rp.SerializeAsString();
res->body(body);
return true;
}
return true;
}

default: // error
{
std::stringstream ss;
Expand Down
25 changes: 24 additions & 1 deletion src/tateyama/proto/endpoint/request.proto
Expand Up @@ -24,8 +24,11 @@ message Request {

// cancel operation.
Cancel cancel = 12;

// shutdown operation.
Shutdown shutdown = 13;
}
reserved 13 to 99;
reserved 14 to 99;
}

// handshake operation.
Expand Down Expand Up @@ -81,3 +84,23 @@ message WireInformation {
message Cancel {
// no special properties.
}

// kind of shutdown type.
enum ShutdownType {

// The default shutdown type.
SHUTDOWN_TYPE_NOT_SET = 0;

// Waits for the ongoing requests and safely shutdown the session.
GRACEFUL = 1;

// Cancelling the ongoing requests and safely shutdown the session.
FORCEFUL = 2;
}

// request shutdown to the session.
message Shutdown {

// the shutdown type.
ShutdownType type = 1;
}
5 changes: 5 additions & 0 deletions src/tateyama/proto/endpoint/response.proto
Expand Up @@ -39,3 +39,8 @@ message Handshake {
uint64 session_id = 11;
}
}

// shutdown operation.
message Shutdown {
// no special message
}

0 comments on commit c10849e

Please sign in to comment.