Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl/handler service endpoints logic workflow abstraction #73

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7f50289
Move is_any_handler_alive as a Server struct method
MS-Painter Jun 14, 2021
acea667
Extract get handler (immutable) logic to Server struct
MS-Painter Jun 15, 2021
2222caf
Extract type TraceHandlerStream to separate file in module
MS-Painter Jun 15, 2021
9f22a0f
Add basis for service endpoints submodule and outsource to it trace_h…
MS-Painter Jun 15, 2021
85f8138
[WIP] Extract handler service server implementations to separate endp…
MS-Painter Jun 15, 2021
972eba1
[WIP] Apply rustfmt
MS-Painter Jun 15, 2021
a4fd853
[WIP] Remove async constraint for is_any_handler_alive logic by movin…
MS-Painter Jun 15, 2021
e398b62
[WIP] cleanup endpoints instantiation with impl new
MS-Painter Jun 15, 2021
09e7c86
Remove unneeded async constraint on Mapping stop_handler logic
MS-Painter Jun 15, 2021
420159a
Rename foldend server module to handler_server
MS-Painter Jun 15, 2021
9931d69
Rename is_any_handler_alive to any_handler_alive (clippy self usage c…
MS-Painter Jun 15, 2021
24725e1
Improve startup_handlers iterations by iterating once
MS-Painter Jun 15, 2021
48cba66
Fix StartHandlerEndpoint and StopHandlerEndpoint PascalCase naming
MS-Painter Jun 15, 2021
2bb7cd3
Use iter_live_handlers in is_concurrent_handlers_limit_reached
MS-Painter Jun 15, 2021
9e0c7ee
Extract is_concurrent_handlers_limit_reached to server utils
MS-Painter Jun 15, 2021
8735555
Removed reliance on Server struct in StartHandlerEndpoint
MS-Painter Jun 15, 2021
86f209b
Outsource spawn_handler_thread logic to HandlerMapping struct
MS-Painter Jun 15, 2021
de0311e
Remove unneeded comment made for spawn handler thread
MS-Painter Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract is_concurrent_handlers_limit_reached to server utils
MS-Painter committed Jun 15, 2021
commit 9e0c7ee7936f731923c38b2493273e59886453fd
9 changes: 5 additions & 4 deletions src/foldend/handler_server/endpoints/register_endpoint.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ use tokio::sync::RwLockWriteGuard;

use super::super::server::Server;
use super::handler_service_endpoint::ServiceEndpoint;
use crate::handler_server::utils::is_concurrent_handlers_limit_reached;
use crate::{handler_mapping::HandlerMapping, mapping::Mapping};
use generated_types::{HandlerStateResponse, RegisterToDirectoryRequest};

@@ -69,10 +70,10 @@ impl ServiceEndpoint<Request, Response> for RegisterEndpoint<'_> {
String::new(),
);
if request.is_start_on_register {
if self
.server
.is_concurrent_handlers_limit_reached(&self.mapping)
{
if is_concurrent_handlers_limit_reached(
&self.mapping,
self.server.config.concurrent_threads_limit,
) {
self.mapping
.directory_mapping
.insert(request.directory_path, handler_mapping);
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use tokio::sync::RwLockWriteGuard;

use super::super::server::Server;
use super::handler_service_endpoint::ServiceEndpoint;
use crate::handler_server::utils::is_concurrent_handlers_limit_reached;
use crate::mapping::Mapping;
use generated_types::{HandlerStateResponse, HandlerStatesMapResponse, StartHandlerRequest};

@@ -44,9 +45,10 @@ impl ServiceEndpoint<Request, Response> for StartHandlerEndpoint<'_> {
{
Some(handler_mapping) => {
if !handler_mapping.is_alive()
&& self
.server
.is_concurrent_handlers_limit_reached(&self.mapping)
&& is_concurrent_handlers_limit_reached(
&self.mapping,
self.server.config.concurrent_threads_limit,
)
{
return Err(tonic::Status::failed_precondition(format!(
"Aborted start handler - Reached concurrent live handler limit ({})",
1 change: 1 addition & 0 deletions src/foldend/handler_server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod endpoints;
mod handler_service;
pub mod server;
mod utils;
19 changes: 1 addition & 18 deletions src/foldend/handler_server/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ops::Deref, sync::Arc};
use std::sync::Arc;

use tokio::sync::{broadcast, RwLock, RwLockReadGuard};

@@ -16,23 +16,6 @@ pub struct Server {
}

impl Server {
pub fn is_concurrent_handlers_limit_reached<T>(&self, mapping: &T) -> bool
where
T: Deref<Target = Mapping>,
{
let mut live_handlers_count: u8 = 0;
if live_handlers_count >= self.config.concurrent_threads_limit {
return true;
}
for _ in mapping.iter_live_handlers() {
live_handlers_count += 1;
if live_handlers_count >= self.config.concurrent_threads_limit {
return true;
}
}
false
}

pub fn convert_trace_channel_reciever_to_stream(
&self,
) -> trace_handler_stream::TraceHandlerStream {
18 changes: 18 additions & 0 deletions src/foldend/handler_server/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use crate::mapping::Mapping;

pub fn is_concurrent_handlers_limit_reached(
mapping: &Mapping,
concurrent_threads_limit: u8,
) -> bool {
let mut live_handlers_count: u8 = 0;
if live_handlers_count >= concurrent_threads_limit {
return true;
}
for _ in mapping.iter_live_handlers() {
live_handlers_count += 1;
if live_handlers_count >= concurrent_threads_limit {
return true;
}
}
false
}