Merge pull request #8730 from Icinga/bugfix/ido-stop-progstat-8727

IDO: update program status on stop
This commit is contained in:
Alexander Aleksandrovič Klimov 2021-07-06 18:07:38 +02:00 committed by GitHub
commit bee83ead8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 34 deletions

View File

@ -87,8 +87,6 @@ void DbConnection::Resume()
void DbConnection::Pause()
{
ConfigObject::Pause();
Log(LogInformation, "DbConnection")
<< "Pausing IDO connection: " << GetName();
@ -105,7 +103,9 @@ void DbConnection::Pause()
query1.Fields = new Dictionary({
{ "instance_id", 0 }, /* DbConnection class fills in real ID */
{ "program_end_time", DbValue::FromTimestamp(Utility::GetTime()) }
{ "program_end_time", DbValue::FromTimestamp(Utility::GetTime()) },
{ "is_currently_running", 0 },
{ "process_id", Empty }
});
query1.Priority = PriorityHigh;
@ -113,6 +113,13 @@ void DbConnection::Pause()
ExecuteQuery(query1);
NewTransaction();
m_QueryQueue.Enqueue([this]() { Disconnect(); }, PriorityLow);
/* Work on remaining tasks but never delete the threads, for HA resuming later. */
m_QueryQueue.Join();
ConfigObject::Pause();
}
void DbConnection::InitializeDbTimer()

View File

@ -75,6 +75,7 @@ protected:
virtual void CleanUpExecuteQuery(const String& table, const String& time_column, double max_age);
virtual void FillIDCache(const DbType::Ptr& type) = 0;
virtual void NewTransaction() = 0;
virtual void Disconnect() = 0;
void UpdateObject(const ConfigObject::Ptr& object);
void UpdateAllObjects();

View File

@ -105,11 +105,6 @@ void IdoMysqlConnection::Pause()
<< "Rescheduling disconnect task.";
#endif /* I2_DEBUG */
m_QueryQueue.Enqueue([this]() { Disconnect(); }, PriorityLow);
/* Work on remaining tasks but never delete the threads, for HA resuming later. */
m_QueryQueue.Join();
Log(LogInformation, "IdoMysqlConnection")
<< "'" << GetName() << "' paused.";
@ -152,7 +147,7 @@ void IdoMysqlConnection::Disconnect()
void IdoMysqlConnection::NewTransaction()
{
if (IsPaused())
if (IsPaused() && GetPauseCalled())
return;
#ifdef I2_DEBUG /* I2_DEBUG */
@ -845,7 +840,9 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va
Value rawvalue = DbValue::ExtractValue(value);
if (rawvalue.IsObjectType<ConfigObject>()) {
if (rawvalue.GetType() == ValueEmpty) {
*result = "NULL";
} else if (rawvalue.IsObjectType<ConfigObject>()) {
DbObject::Ptr dbobjcol = DbObject::GetOrCreateByObject(rawvalue);
if (!dbobjcol) {
@ -906,7 +903,7 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va
void IdoMysqlConnection::ExecuteQuery(const DbQuery& query)
{
if (IsPaused())
if (IsPaused() && GetPauseCalled())
return;
ASSERT(query.Category != DbCatInvalid);
@ -958,9 +955,6 @@ bool IdoMysqlConnection::CanExecuteQuery(const DbQuery& query)
for (const Dictionary::Pair& kv : query.Fields) {
Value value;
if (kv.second.IsEmpty() && !kv.second.IsString())
continue;
if (!FieldToEscapedString(kv.first, kv.second, &value))
return false;
}
@ -1009,7 +1003,7 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
{
AssertOnWorkQueue();
if (IsPaused()) {
if (IsPaused() && GetPauseCalled()) {
DecreasePendingQueries(1);
return;
}
@ -1137,9 +1131,6 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
for (const Dictionary::Pair& kv : query.Fields) {
Value value;
if (kv.second.IsEmpty() && !kv.second.IsString())
continue;
if (!FieldToEscapedString(kv.first, kv.second, &value)) {
#ifdef I2_DEBUG /* I2_DEBUG */

View File

@ -51,6 +51,7 @@ protected:
void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) override;
void FillIDCache(const DbType::Ptr& type) override;
void NewTransaction() override;
void Disconnect() override;
private:
DbReference m_InstanceID;
@ -82,7 +83,6 @@ private:
void InternalActivateObject(const DbObject::Ptr& dbobj);
void InternalDeactivateObject(const DbObject::Ptr& dbobj);
void Disconnect();
void Reconnect();
void AssertOnWorkQueue();

View File

@ -104,11 +104,6 @@ void IdoPgsqlConnection::Pause()
m_ReconnectTimer.reset();
m_QueryQueue.Enqueue([this]() { Disconnect(); }, PriorityLow);
/* Work on remaining tasks but never delete the threads, for HA resuming later. */
m_QueryQueue.Join();
Log(LogInformation, "IdoPgsqlConnection")
<< "'" << GetName() << "' paused.";
}
@ -659,7 +654,9 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
Value rawvalue = DbValue::ExtractValue(value);
if (rawvalue.IsObjectType<ConfigObject>()) {
if (rawvalue.GetType() == ValueEmpty) {
*result = "NULL";
} else if (rawvalue.IsObjectType<ConfigObject>()) {
DbObject::Ptr dbobjcol = DbObject::GetOrCreateByObject(rawvalue);
if (!dbobjcol) {
@ -720,7 +717,7 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
void IdoPgsqlConnection::ExecuteQuery(const DbQuery& query)
{
if (IsPaused())
if (IsPaused() && GetPauseCalled())
return;
ASSERT(query.Category != DbCatInvalid);
@ -762,9 +759,6 @@ bool IdoPgsqlConnection::CanExecuteQuery(const DbQuery& query)
for (const Dictionary::Pair& kv : query.Fields) {
Value value;
if (kv.second.IsEmpty() && !kv.second.IsString())
continue;
if (!FieldToEscapedString(kv.first, kv.second, &value))
return false;
}
@ -805,7 +799,7 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
{
AssertOnWorkQueue();
if (IsPaused()) {
if (IsPaused() && GetPauseCalled()) {
DecreasePendingQueries(1);
return;
}
@ -918,9 +912,6 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query, int typeOver
Value value;
bool first = true;
for (const Dictionary::Pair& kv : query.Fields) {
if (kv.second.IsEmpty() && !kv.second.IsString())
continue;
if (!FieldToEscapedString(kv.first, kv.second, &value)) {
m_QueryQueue.Enqueue([this, query]() { InternalExecuteQuery(query, -1); }, query.Priority);
return;

View File

@ -44,6 +44,7 @@ protected:
void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) override;
void FillIDCache(const DbType::Ptr& type) override;
void NewTransaction() override;
void Disconnect() override;
private:
DbReference m_InstanceID;
@ -67,7 +68,6 @@ private:
void InternalActivateObject(const DbObject::Ptr& dbobj);
void InternalDeactivateObject(const DbObject::Ptr& dbobj);
void Disconnect();
void InternalNewTransaction();
void Reconnect();