]> granicus.if.org Git - icinga2/commitdiff
Improve performance for ApiListener::RelayMessageOne
authorGunnar Beutner <gunnar@beutner.name>
Wed, 27 Jan 2016 12:39:31 +0000 (13:39 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Wed, 27 Jan 2016 12:39:31 +0000 (13:39 +0100)
refs #11014

lib/remote/apilistener.cpp
lib/remote/apilistener.hpp

index de9f1047d673b76c9c59e024288b994d42ba9b79..6cad26bbb19cf2e6a469a55c7fe28a77c5623a1c 100644 (file)
@@ -613,18 +613,18 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar
        }
 }
 
-bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message)
+bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message, const Endpoint::Ptr& currentMaster)
 {
        ASSERT(targetZone);
 
-       bool is_master = IsMaster();
-       Endpoint::Ptr master = GetMaster();
        Zone::Ptr myZone = Zone::GetLocalZone();
 
        /* only relay the message to a) the same zone, b) the parent zone and c) direct child zones */
        if (targetZone != myZone && targetZone != myZone->GetParent() && targetZone->GetParent() != myZone)
                return true;
 
+       Endpoint::Ptr myEndpoint = GetLocalEndpoint();
+
        std::vector<Endpoint::Ptr> skippedEndpoints;
 
        bool relayed = false, log_needed = false, log_done = false;
@@ -665,7 +665,7 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
                }
 
                /* only relay message to the master if we're not currently the master */
-               if (!is_master && master != endpoint) {
+               if (currentMaster != myEndpoint && currentMaster != endpoint) {
                        skippedEndpoints.push_back(endpoint);
                        continue;
                }
@@ -709,10 +709,12 @@ void ApiListener::SyncRelayMessage(const MessageOrigin::Ptr& origin,
        if (!target_zone)
                target_zone = Zone::GetLocalZone();
 
-       bool need_log = !RelayMessageOne(target_zone, origin, message);
+       Endpoint::Ptr master = GetMaster();
+
+       bool need_log = !RelayMessageOne(target_zone, origin, message, master);
 
        BOOST_FOREACH(const Zone::Ptr& zone, target_zone->GetAllParents()) {
-               if (!RelayMessageOne(zone, origin, message))
+               if (!RelayMessageOne(zone, origin, message, master))
                        need_log = true;
        }
 
index 5fcbea3b1548576b10bde53f0d75bf48b56365e5..bfc2f2d7a525bed1d4bf545f37060d61ec9e9af8 100644 (file)
@@ -128,7 +128,7 @@ private:
        Stream::Ptr m_LogFile;
        size_t m_LogMessageCount;
 
-       bool RelayMessageOne(const Zone::Ptr& zone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message);
+       bool RelayMessageOne(const Zone::Ptr& zone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message, const Endpoint::Ptr& currentMaster);
        void SyncRelayMessage(const MessageOrigin::Ptr& origin, const ConfigObject::Ptr& secobj, const Dictionary::Ptr& message, bool log);
        void PersistMessage(const Dictionary::Ptr& message, const ConfigObject::Ptr& secobj);