Merge pull request #8363 from Icinga/bugfix/ido-commit-25000-213

IDO MySQL: actually COMMIT after 25000 async queries
This commit is contained in:
Alexander Aleksandrovič Klimov 2020-10-14 16:00:39 +02:00 committed by GitHub
commit e8316952f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -513,11 +513,6 @@ void IdoMysqlConnection::AsyncQuery(const String& query, const std::function<voi
*/
aq.Callback = callback;
m_AsyncQueries.emplace_back(std::move(aq));
if (m_AsyncQueries.size() > 25000) {
FinishAsyncQueries();
InternalNewTransaction();
}
}
void IdoMysqlConnection::FinishAsyncQueries()
@ -547,6 +542,7 @@ void IdoMysqlConnection::FinishAsyncQueries()
Defer decreaseQueries ([this, &offset, &count]() {
offset += count;
DecreasePendingQueries(count);
m_UncommittedAsyncQueries += count;
});
for (std::vector<IdoAsyncQuery>::size_type i = offset; i < queries.size(); i++) {
@ -628,6 +624,13 @@ void IdoMysqlConnection::FinishAsyncQueries()
}
}
}
if (m_UncommittedAsyncQueries > 25000) {
m_UncommittedAsyncQueries = 0;
Query("COMMIT");
Query("BEGIN");
}
}
IdoMysqlResult IdoMysqlConnection::Query(const String& query)

View File

@ -9,6 +9,7 @@
#include "base/timer.hpp"
#include "base/workqueue.hpp"
#include "base/library.hpp"
#include <cstdint>
namespace icinga
{
@ -64,6 +65,7 @@ private:
unsigned int m_MaxPacketSize;
std::vector<IdoAsyncQuery> m_AsyncQueries;
uint_fast32_t m_UncommittedAsyncQueries = 0;
Timer::Ptr m_ReconnectTimer;
Timer::Ptr m_TxTimer;