ApiListener: Process cluster config updates sequentially

This commit is contained in:
Yonas Habteab 2024-02-13 14:52:20 +01:00
parent 40011b0584
commit 456144c1dc
2 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include "base/configtype.hpp"
#include "base/json.hpp"
#include "base/convert.hpp"
#include "base/defer.hpp"
#include "config/vmops.hpp"
#include <fstream>
@ -104,6 +105,15 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
return Empty;
}
// Wait for the object name to become available for processing and block it immediately.
// Doing so guarantees that only one cluster event (create/update/delete) of a given
// object is being processed at any given time.
listener->m_ObjectConfigChangeLock.Lock(ptype, objName);
Defer unlockAndNotify([&listener, &ptype, &objName]{
listener->m_ObjectConfigChangeLock.Unlock(ptype, objName);
});
ConfigObject::Ptr object = ctype->GetObject(objName);
String config = params->Get("config");
@ -258,6 +268,15 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin
return Empty;
}
// Wait for the object name to become available for processing and block it immediately.
// Doing so guarantees that only one cluster event (create/update/delete) of a given
// object is being processed at any given time.
listener->m_ObjectConfigChangeLock.Lock(ptype, objName);
Defer unlockAndNotify([&listener, &ptype, &objName]{
listener->m_ObjectConfigChangeLock.Unlock(ptype, objName);
});
ConfigObject::Ptr object = ctype->GetObject(objName);
if (!object) {

View File

@ -277,6 +277,9 @@ private:
mutable std::mutex m_ActivePackageStagesLock;
std::map<String, String> m_ActivePackageStages;
/* ensures that at most one create/update/delete is being processed per object at each time */
mutable ObjectNameMutex m_ObjectConfigChangeLock;
void UpdateActivePackageStagesCache();
};