Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update object#config_hash after all relations queries #10131

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/db_ido/dbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ void DbObject::SendConfigUpdateHeavy(const Dictionary::Ptr& configFields)

ASSERT(configFields->Contains("config_hash"));

Value configHash = configFields->Get("config_hash");
// Since all the child tables are relying on the inserted parent ID, we first need to insert/update the
// configuration fields of the current object without the actual config_hash value. Having the config hash
// set only after all relation queries eliminates some rare race conditions where e.g. host group members
// are not written to the database because Icinga 2 / the DBMS was unexpectedly stopped/reloaded shortly
// after the config_hash column was updated.
configFields->Set("config_hash", Empty);

ConfigObject::Ptr object = GetObject();

DbQuery query;
Expand All @@ -138,7 +146,22 @@ void DbObject::SendConfigUpdateHeavy(const Dictionary::Ptr& configFields)

m_LastConfigUpdate = Utility::GetTime();

// Trigger config heavy udpates of the child classes.
OnConfigUpdateHeavy();

// Now update the config hash attribute of the current object.
DbQuery configHashQuery;
configHashQuery.Table = GetType()->GetTable() + "s";
configHashQuery.Type = DbQueryUpdate;
configHashQuery.Category = DbCatConfig;
configHashQuery.Fields = new Dictionary({{"config_hash", configHash}});
configHashQuery.Object = this;
configHashQuery.ConfigUpdate = true;
configHashQuery.WhereCriteria = new Dictionary({{GetType()->GetIDColumn(), object}});
OnQuery(configHashQuery);

// Lastly, update some common configs that do not affect the config_hash column.
OnConfigUpdateLight();
}

void DbObject::SendConfigUpdateLight()
Expand Down
2 changes: 0 additions & 2 deletions lib/db_ido/hostdbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,6 @@ void HostDbObject::OnConfigUpdateHeavy()
}

DbObject::OnMultipleQueries(queries);

DoCommonConfigUpdate();
}

void HostDbObject::OnConfigUpdateLight()
Expand Down
2 changes: 0 additions & 2 deletions lib/db_ido/servicedbobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ void ServiceDbObject::OnConfigUpdateHeavy()
}

DbObject::OnMultipleQueries(queries);

DoCommonConfigUpdate();
}

void ServiceDbObject::OnConfigUpdateLight()
Expand Down
Loading