]> granicus.if.org Git - icinga2/commitdiff
Ensure that config sync updates are always sent on reconnect
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 4 Feb 2016 10:30:27 +0000 (11:30 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 4 Feb 2016 10:30:27 +0000 (11:30 +0100)
fixes #11083

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

index 6cad26bbb19cf2e6a469a55c7fe28a77c5623a1c..37d37303429c5b72e3ec0e84008b0768ab8ff37a 100644 (file)
@@ -339,11 +339,6 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
                    << "New client connection (no client certificate)";
        }
 
-       bool need_sync = false;
-
-       if (endpoint)
-               need_sync = !endpoint->GetConnected();
-
        ClientType ctype;
 
        if (role == RoleClient) {
@@ -377,10 +372,11 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
                aclient->Start();
 
                if (endpoint) {
+                       bool needSync = !endpoint->GetConnected();
+
                        endpoint->AddClient(aclient);
 
-                       if (need_sync)
-                               m_SyncQueue.Enqueue(boost::bind(&ApiListener::SyncClient, this, aclient, endpoint));
+                       m_SyncQueue.Enqueue(boost::bind(&ApiListener::SyncClient, this, aclient, endpoint, needSync));
                } else
                        AddAnonymousClient(aclient);
        } else {
@@ -392,7 +388,7 @@ void ApiListener::NewClientHandlerInternal(const Socket::Ptr& client, const Stri
        }
 }
 
-void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint)
+void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync)
 {
        try {
                {
@@ -401,8 +397,12 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
                        endpoint->SetSyncing(true);
                }
 
+               /* Make sure that the config updates are synced
+                * before the logs are replayed.
+                */
+
                Log(LogInformation, "ApiListener")
-                   << "Sending updates for endpoint '" << endpoint->GetName() << "'.";
+                   << "Sending config updates for endpoint '" << endpoint->GetName() << "'.";
 
                /* sync zone file config */
                SendConfigUpdate(aclient);
@@ -410,9 +410,19 @@ void ApiListener::SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoi
                SendRuntimeConfigObjects(aclient);
 
                Log(LogInformation, "ApiListener")
-                   << "Finished sending updates for endpoint '" << endpoint->GetName() << "'.";
+                   << "Finished sending config updates for endpoint '" << endpoint->GetName() << "'.";
+
+               if (!needSync)
+                       return;
+
+               Log(LogInformation, "ApiListener")
+                   << "Sending replay log for endpoint '" << endpoint->GetName() << "'.";
 
                ReplayLog(aclient);
+
+               Log(LogInformation, "ApiListener")
+                   << "Finished sending replay log for endpoint '" << endpoint->GetName() << "'.";
+
        } catch (const std::exception& ex) {
                Log(LogCritical, "ApiListener")
                    << "Error while syncing endpoint '" << endpoint->GetName() << "': " << DiagnosticInformation(ex);
index bfc2f2d7a525bed1d4bf545f37060d61ec9e9af8..4c860f89bbbf615e95db3ee11618790f4cedf226 100644 (file)
@@ -156,7 +156,7 @@ private:
            const JsonRpcConnection::Ptr& client = JsonRpcConnection::Ptr());
        void SendRuntimeConfigObjects(const JsonRpcConnection::Ptr& aclient);
 
-       void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint);
+       void SyncClient(const JsonRpcConnection::Ptr& aclient, const Endpoint::Ptr& endpoint, bool needSync);
 };
 
 }