Zone#GetEndpoints(): return endpoints in the specified order, not randomly

ApiListener#RelayMessageOne() relays every given message to the first connected endpoint Zone#GetEndpoints() returns. Randomness in combination with bad luck can direct more traffic (from a particular network segment) to one master than the admin wants.

This change lets the Zone#endpoints order prefer one endpoint over the other.
This commit is contained in:
Alexander A. Klimov 2025-03-25 13:04:41 +01:00
parent 5e902fe4a7
commit a943c4588b
5 changed files with 7 additions and 9 deletions

View File

@ -932,7 +932,7 @@ Dictionary::Ptr ApiActions::ExecuteCommand(const ConfigObject::Ptr& object, cons
for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointPtr->GetZone())) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
auto endpoints (zone->GetEndpoints());
for (const Endpoint::Ptr& childEndpoint : endpoints) {
if (!(childEndpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand)) {

View File

@ -966,7 +966,7 @@ Value ClusterEvents::ExecuteCommandAPIHandler(const MessageOrigin::Ptr& origin,
for (const Zone::Ptr &zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
auto endpoints (zone->GetEndpoints());
for (const Endpoint::Ptr &childEndpoint : endpoints) {
if (!(childEndpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand)) {

View File

@ -70,8 +70,7 @@ Value ZonesTable::EndpointsAccessor(const Value& row)
if (!zone)
return Empty;
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
auto endpoints (zone->GetEndpoints());
ArrayData result;
for (const Endpoint::Ptr& endpoint : endpoints) {

View File

@ -51,10 +51,9 @@ Zone::Ptr Zone::GetParent() const
return m_Parent;
}
std::set<Endpoint::Ptr> Zone::GetEndpoints() const
std::vector<Endpoint::Ptr> Zone::GetEndpoints() const
{
std::set<Endpoint::Ptr> result;
std::vector<Endpoint::Ptr> result;
Array::Ptr endpoints = GetEndpointsRaw();
if (endpoints) {
@ -66,7 +65,7 @@ std::set<Endpoint::Ptr> Zone::GetEndpoints() const
if (!endpoint)
continue;
result.insert(endpoint);
result.emplace_back(std::move(endpoint));
}
}

View File

@ -22,7 +22,7 @@ public:
void OnAllConfigLoaded() override;
Zone::Ptr GetParent() const;
std::set<Endpoint::Ptr> GetEndpoints() const;
std::vector<Endpoint::Ptr> GetEndpoints() const;
std::vector<Zone::Ptr> GetAllParentsRaw() const;
Array::Ptr GetAllParents() const override;