Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
5a471181
Commit
5a471181
authored
Oct 06, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Actively manage monitoring in BASP broker
parent
dcc67675
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
29 deletions
+55
-29
libcaf_io/caf/io/basp_broker.hpp
libcaf_io/caf/io/basp_broker.hpp
+13
-0
libcaf_io/src/basp_broker.cpp
libcaf_io/src/basp_broker.cpp
+42
-29
No files found.
libcaf_io/caf/io/basp_broker.hpp
View file @
5a471181
...
@@ -138,6 +138,19 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
...
@@ -138,6 +138,19 @@ struct basp_broker_state : proxy_registry::backend, basp::instance::callee {
return
instance
.
this_node
();
return
instance
.
this_node
();
}
}
using
monitored_actor_map
=
std
::
unordered_map
<
actor_addr
,
std
::
unordered_set
<
node_id
>>
;
// keeps a list of nodes that monitor a particular local actor
monitored_actor_map
monitored_actors
;
// sends a kill_proxy message to a remote node
void
send_kill_proxy_instance
(
const
node_id
&
nid
,
actor_id
aid
,
error
err
);
// sends kill_proxy_instance message to all nodes monitoring the terminated
// actor
void
handle_down_msg
(
down_msg
&
);
static
const
char
*
name
;
static
const
char
*
name
;
};
};
...
...
libcaf_io/src/basp_broker.cpp
View file @
5a471181
...
@@ -162,48 +162,59 @@ void basp_broker_state::purge_state(const node_id& nid) {
...
@@ -162,48 +162,59 @@ void basp_broker_state::purge_state(const node_id& nid) {
}
}
// Destroy all proxies of the lost node.
// Destroy all proxies of the lost node.
namespace_
.
erase
(
nid
);
namespace_
.
erase
(
nid
);
// Cleanup all possible remaining references to the lost node.
for
(
auto
&
kvp
:
monitored_actors
)
kvp
.
second
.
erase
(
nid
);
// Close network connection.
// Close network connection.
self
->
close
(
hdl
);
self
->
close
(
hdl
);
}
}
void
basp_broker_state
::
send_kill_proxy_instance
(
const
node_id
&
nid
,
actor_id
aid
,
error
rsn
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
)
<<
CAF_ARG
(
rsn
));
if
(
rsn
==
none
)
rsn
=
exit_reason
::
unknown
;
auto
path
=
instance
.
tbl
().
lookup
(
nid
);
if
(
!
path
)
{
CAF_LOG_INFO
(
"cannot send exit message for proxy, no route to host:"
<<
CAF_ARG
(
nid
));
return
;
}
instance
.
write_kill_proxy
(
self
->
context
(),
path
->
wr_buf
,
nid
,
aid
,
rsn
);
instance
.
tbl
().
flush
(
*
path
);
}
void
basp_broker_state
::
proxy_announced
(
const
node_id
&
nid
,
actor_id
aid
)
{
void
basp_broker_state
::
proxy_announced
(
const
node_id
&
nid
,
actor_id
aid
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
));
CAF_LOG_TRACE
(
CAF_ARG
(
nid
)
<<
CAF_ARG
(
aid
));
// source node has created a proxy for one of our actors
// source node has created a proxy for one of our actors
auto
entry
=
system
().
registry
().
get
(
aid
);
auto
ptr
=
system
().
registry
().
get
(
aid
);
auto
send_kill_proxy_instance
=
[
=
](
error
rsn
)
{
if
(
!
rsn
)
rsn
=
exit_reason
::
unknown
;
auto
path
=
instance
.
tbl
().
lookup
(
nid
);
if
(
!
path
)
{
CAF_LOG_INFO
(
"cannot send exit message for proxy, no route to host:"
<<
CAF_ARG
(
nid
));
return
;
}
instance
.
write_kill_proxy
(
self
->
context
(),
path
->
wr_buf
,
nid
,
aid
,
rsn
);
instance
.
tbl
().
flush
(
*
path
);
};
auto
ptr
=
actor_cast
<
strong_actor_ptr
>
(
entry
);
if
(
ptr
==
nullptr
)
{
if
(
ptr
==
nullptr
)
{
CAF_LOG_DEBUG
(
"kill proxy immediately"
);
CAF_LOG_DEBUG
(
"kill proxy immediately"
);
// kill immediately if actor has already terminated
// kill immediately if actor has already terminated
send_kill_proxy_instance
(
exit_reason
::
unknown
);
send_kill_proxy_instance
(
nid
,
aid
,
exit_reason
::
unknown
);
}
else
{
}
else
{
strong_actor_ptr
tmp
{
self
->
ctrl
()};
auto
entry
=
ptr
->
address
();
auto
mm
=
&
system
().
middleman
();
auto
i
=
monitored_actors
.
find
(
entry
);
ptr
->
get
()
->
attach_functor
([
=
](
const
error
&
fail_state
)
{
if
(
i
==
monitored_actors
.
end
())
{
mm
->
backend
().
dispatch
([
=
]
{
self
->
monitor
(
ptr
);
CAF_LOG_TRACE
(
CAF_ARG
(
fail_state
));
std
::
unordered_set
<
node_id
>
tmp
{
nid
};
auto
bptr
=
static_cast
<
basp_broker
*>
(
tmp
->
get
());
monitored_actors
.
emplace
(
entry
,
std
::
move
(
tmp
));
// ... to make sure this is safe
}
else
{
if
(
bptr
==
mm
->
named_broker
<
basp_broker
>
(
atom
(
"BASP"
))
i
->
second
.
emplace
(
nid
);
&&
!
bptr
->
getf
(
abstract_actor
::
is_terminated_flag
))
}
send_kill_proxy_instance
(
fail_state
);
});
});
}
}
}
}
void
basp_broker_state
::
handle_down_msg
(
down_msg
&
dm
)
{
auto
i
=
monitored_actors
.
find
(
dm
.
source
);
if
(
i
==
monitored_actors
.
end
())
return
;
for
(
auto
&
nid
:
i
->
second
)
send_kill_proxy_instance
(
nid
,
dm
.
source
.
id
(),
dm
.
reason
);
monitored_actors
.
erase
(
i
);
}
void
basp_broker_state
::
deliver
(
const
node_id
&
src_nid
,
actor_id
src_aid
,
void
basp_broker_state
::
deliver
(
const
node_id
&
src_nid
,
actor_id
src_aid
,
actor_id
dest_aid
,
message_id
mid
,
actor_id
dest_aid
,
message_id
mid
,
std
::
vector
<
strong_actor_ptr
>&
stages
,
std
::
vector
<
strong_actor_ptr
>&
stages
,
...
@@ -481,7 +492,9 @@ void basp_broker_state::set_context(connection_handle hdl) {
...
@@ -481,7 +492,9 @@ void basp_broker_state::set_context(connection_handle hdl) {
basp_broker
::
basp_broker
(
actor_config
&
cfg
)
basp_broker
::
basp_broker
(
actor_config
&
cfg
)
:
stateful_actor
<
basp_broker_state
,
broker
>
(
cfg
)
{
:
stateful_actor
<
basp_broker_state
,
broker
>
(
cfg
)
{
// nop
set_down_handler
([](
local_actor
*
ptr
,
down_msg
&
x
)
{
static_cast
<
basp_broker
*>
(
ptr
)
->
state
.
handle_down_msg
(
x
);
});
}
}
behavior
basp_broker
::
make_behavior
()
{
behavior
basp_broker
::
make_behavior
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment