]> granicus.if.org Git - icinga2/commitdiff
IDO MySQL: Don't immediately execute an upsert insert query callback
authorMichael Friedrich <michael.friedrich@icinga.com>
Wed, 22 Feb 2017 15:32:31 +0000 (16:32 +0100)
committerGunnar Beutner <gunnar.beutner@icinga.com>
Thu, 2 Mar 2017 09:16:18 +0000 (10:16 +0100)
refs #4603

lib/db_ido_mysql/idomysqlconnection.cpp

index c3e9cdce3a88743a9edc048f817359314cb96557..9c5c2632234a66193b9d25cef1dddf137f26d87b 100644 (file)
@@ -475,6 +475,9 @@ void IdoMysqlConnection::AsyncQuery(const String& query, const boost::function<v
 
        IdoAsyncQuery aq;
        aq.Query = query;
+       /* XXX: Important: The callback must not immediately execute a query, but enqueue it!
+        * See https://github.com/Icinga/icinga2/issues/4603 for details.
+        */
        aq.Callback = callback;
        m_AsyncQueries.push_back(aq);
 
@@ -1088,7 +1091,13 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
 void IdoMysqlConnection::FinishExecuteQuery(const DbQuery& query, int type, bool upsert)
 {
        if (upsert && GetAffectedRows() == 0) {
-               InternalExecuteQuery(query, DbQueryDelete | DbQueryInsert);
+
+#ifdef I2_DEBUG /* I2_DEBUG */
+               Log(LogDebug, "IdoMysqlConnection")
+                   << "Rescheduling DELETE/INSERT query: Upsert UPDATE did not affect rows, type " << type << ", table '" << query.Table << "'.";
+#endif /* I2_DEBUG */
+
+               m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalExecuteQuery, this, query, DbQueryDelete | DbQueryInsert), query.Priority);
 
                return;
        }