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 committed by Julian Brost
parent cf9ca50d19
commit fc70825cb2
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>()) { for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */ /* Fetch immediate child zone members */
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointPtr->GetZone())) { 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) { for (const Endpoint::Ptr& childEndpoint : endpoints) {
if (!(childEndpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand)) { 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>()) { for (const Zone::Ptr &zone : ConfigType::GetObjectsByType<Zone>()) {
/* Fetch immediate child zone members */ /* Fetch immediate child zone members */
if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) { if (zone->GetParent() == localZone && zone->CanAccessObject(endpointZone)) {
std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints(); auto endpoints (zone->GetEndpoints());
for (const Endpoint::Ptr &childEndpoint : endpoints) { for (const Endpoint::Ptr &childEndpoint : endpoints) {
if (!(childEndpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand)) { if (!(childEndpoint->GetCapabilities() & (uint_fast64_t)ApiCapabilities::ExecuteArbitraryCommand)) {

View File

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

View File

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

View File

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