Skip to content

Commit

Permalink
ApiListener: Process cluster config updates sequentially
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Feb 13, 2024
1 parent 215daeb commit 087c8b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -104,6 +105,13 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
return Empty;
}

// Wait for the object name to become available for processing and block it immediately.
listener->m_ObjectConfigChangeLock.WaitForObject(ptype, objName);

Defer unlockAndNotifyOne([&listener, &ptype, &objName]{
listener->m_ObjectConfigChangeLock.UnBlockNotify(ptype, objName);
});

ConfigObject::Ptr object = ctype->GetObject(objName);

String config = params->Get("config");
Expand Down Expand Up @@ -258,6 +266,13 @@ Value ApiListener::ConfigDeleteObjectAPIHandler(const MessageOrigin::Ptr& origin
return Empty;
}

// Wait for the object name to become available for processing and block it immediately.
listener->m_ObjectConfigChangeLock.WaitForObject(ptype, objName);

Defer unblockAndNotifyOne([&listener, &ptype, &objName]{
listener->m_ObjectConfigChangeLock.UnBlockNotify(ptype, objName);
});

ConfigObject::Ptr object = ctype->GetObject(objName);

if (!object) {
Expand Down
3 changes: 3 additions & 0 deletions lib/remote/apilistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ class ApiListener final : public ObjectImpl<ApiListener>
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();
};

Expand Down

0 comments on commit 087c8b5

Please sign in to comment.