]> granicus.if.org Git - icinga2/commitdiff
DB IDO: Do not deactivate objects during application reload/restart
authorMichael Friedrich <michael.friedrich@icinga.com>
Fri, 3 May 2019 10:44:29 +0000 (12:44 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 16 May 2019 13:22:16 +0000 (15:22 +0200)
This follows the same principle as with the shutdown handler,
and was introduced with the changed reload handling with 2.9.
Previously IsShuttingDown() was sufficient which got set at one
location.

SigUsr2 as handler introduced a new location where m_ShuttingDown
is not necessarily set yet. Since this handler gets called when
l_Restarting is enabled, we'll use this flag to avoid config update
events resulting in object deactivation (object->IsActive() always
returns false).

refs #5996
refs #6691
refs #6970

fixes #7125

(cherry picked from commit 78e24c53f1564269f744de5efe50cb099cadbdde)

lib/base/application.cpp
lib/base/application.hpp
lib/db_ido/dbconnection.cpp

index 2ccf275b6b67da5175342e65cb1e6f150a55202f..4528808d1902be503e3e569ef1a0ba929fe942c5 100644 (file)
@@ -374,6 +374,11 @@ bool Application::IsShuttingDown()
        return m_ShuttingDown;
 }
 
+bool Application::IsRestarting()
+{
+       return l_Restarting;
+}
+
 void Application::OnShutdown()
 {
        /* Nothing to do here. */
index d88e65a7afff54efce1428b9a5252b2dd6cb78e6..1f0d4dad45488956b40a26d2116ef94a6d9d9d12 100644 (file)
@@ -75,6 +75,7 @@ public:
        static void RequestReopenLogs();
 
        static bool IsShuttingDown();
+       static bool IsRestarting();
 
        static void SetDebuggingSeverity(LogSeverity severity);
        static LogSeverity GetDebuggingSeverity();
index b8e1a50f2e0525b45718e78f9b61409c52a9eb80..44782dbee75faa42a8609d394f79695040c8167a 100644 (file)
@@ -392,7 +392,26 @@ bool DbConnection::GetStatusUpdate(const DbObject::Ptr& dbobj) const
 
 void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
 {
-       if (!GetConnected() || Application::IsShuttingDown())
+       bool isShuttingDown = Application::IsShuttingDown();
+       bool isRestarting = Application::IsRestarting();
+
+#ifdef I2_DEBUG
+       if (isShuttingDown || isRestarting) {
+               //Log(LogDebug, "DbConnection")
+               //      << "Updating object '" << object->GetName() << "' \t\t active '" << Convert::ToLong(object->IsActive())
+               //      << "' shutting down '" << Convert::ToLong(isShuttingDown) << "' restarting '" << Convert::ToLong(isRestarting) << "'.";
+       }
+#endif /* I2_DEBUG */
+
+       /* Wait until a database connection is established on reconnect. */
+       if (!GetConnected())
+               return;
+
+       /* Don't update inactive objects during shutdown/reload/restart.
+        * They would be marked as deleted. This gets triggered with ConfigObject::StopObjects().
+        * During startup/reconnect this is fine, the handler is not active there.
+        */
+       if (isShuttingDown || isRestarting)
                return;
 
        DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object);
@@ -419,7 +438,10 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
                                dbobj->SendConfigUpdateLight();
                        }
                } else if (!active) {
-                       /* Deactivate the deleted object no matter
+                       /* This may happen on reload/restart actions too
+                        * and is blocked above already.
+                        *
+                        * Deactivate the deleted object no matter
                         * which state it had in the database.
                         */
                        DeactivateObject(dbobj);