Skip to content

Commit 2ac1d7b

Browse files
committed
ApiListener::UpdateObjectAuthority(): distribute auth. by object's host
Pin child objects of hosts (HOST!...) to the same endpoint as the host. This reduces cross-object action latency withing the same host. If all endpoints know this algorithm, we can use it.
1 parent daab7d5 commit 2ac1d7b

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

lib/remote/apilistener-authority.cpp

+24-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ void ApiListener::UpdateObjectAuthority()
2525

2626
std::vector<Endpoint::Ptr> endpoints;
2727
Endpoint::Ptr my_endpoint;
28+
int hostChildrenInheritObjectAuthority = 0;
2829

2930
if (my_zone) {
3031
my_endpoint = Endpoint::GetLocalEndpoint();
@@ -51,6 +52,12 @@ void ApiListener::UpdateObjectAuthority()
5152
return a->GetName() < b->GetName();
5253
}
5354
);
55+
56+
for (auto& endpoint : endpoints) {
57+
if (endpoint == my_endpoint || endpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::HostChildrenInheritObjectAuthority) {
58+
++hostChildrenInheritObjectAuthority;
59+
}
60+
}
5461
}
5562

5663
for (const Type::Ptr& type : Type::GetAllTypes()) {
@@ -65,10 +72,24 @@ void ApiListener::UpdateObjectAuthority()
6572

6673
bool authority;
6774

68-
if (!my_zone)
75+
if (my_zone) {
76+
auto name (object->GetName());
77+
78+
// If all endpoints know this algorithm, we can use it.
79+
if (hostChildrenInheritObjectAuthority == endpoints.size()) {
80+
auto exclamation (name.FindFirstOf('!'));
81+
82+
// Pin child objects of hosts (HOST!...) to the same endpoint as the host.
83+
// This reduces cross-object action latency withing the same host.
84+
if (exclamation != String::NPos) {
85+
name = name.SubStr(0, exclamation);
86+
}
87+
}
88+
89+
authority = endpoints[Utility::SDBM(name) % endpoints.size()] == my_endpoint;
90+
} else {
6991
authority = true;
70-
else
71-
authority = endpoints[Utility::SDBM(object->GetName()) % endpoints.size()] == my_endpoint;
92+
}
7293

7394
#ifdef I2_DEBUG
7495
// //Enable on demand, causes heavy logging on each run.

lib/remote/apilistener.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ static const auto l_AppVersionInt (([]() -> unsigned long {
644644
})());
645645

646646
static const auto l_MyCapabilities (
647-
(uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand | (uint_fast64_t)ApiCapabilities::IfwApiCheckCommand
647+
(uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand
648+
| (uint_fast64_t)ApiCapabilities::IfwApiCheckCommand
649+
| (uint_fast64_t)ApiCapabilities::HostChildrenInheritObjectAuthority
648650
);
649651

650652
/**

lib/remote/apilistener.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ enum class ApiCapabilities : uint_fast64_t
6969
{
7070
ExecuteArbitraryCommand = 1u << 0u,
7171
IfwApiCheckCommand = 1u << 1u,
72+
HostChildrenInheritObjectAuthority = 1u << 2u,
7273
};
7374

7475
/**

0 commit comments

Comments
 (0)