ApiListener::HandleConfigUpdate(): make the whole process mutually exclusive

refs #7742
This commit is contained in:
Alexander A. Klimov 2020-03-23 17:33:14 +01:00
parent dc3062a9b0
commit 38f3108c1a
2 changed files with 9 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include "base/convert.hpp"
#include "base/application.hpp"
#include "base/exception.hpp"
#include "base/shared.hpp"
#include "base/utility.hpp"
#include <fstream>
#include <iomanip>
@ -320,7 +321,7 @@ void ApiListener::HandleConfigUpdate(const MessageOrigin::Ptr& origin, const Dic
/* Only one transaction is allowed, concurrent message handlers need to wait.
* This affects two parent endpoints sending the config in the same moment.
*/
boost::mutex::scoped_lock lock(m_ConfigSyncStageLock);
auto lock (Shared<boost::mutex::scoped_lock>::Make(m_ConfigSyncStageLock));
String apiZonesStageDir = GetApiZonesStageDir();
String fromEndpointName = origin->FromClient->GetEndpoint()->GetName();
@ -528,7 +529,7 @@ void ApiListener::HandleConfigUpdate(const MessageOrigin::Ptr& origin, const Dic
Log(LogInformation, "ApiListener")
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
<< "' are different to production, triggering validation and reload.";
AsyncTryActivateZonesStage(relativePaths);
AsyncTryActivateZonesStage(relativePaths, lock);
} else {
Log(LogInformation, "ApiListener")
<< "Received configuration updates (" << count << ") from endpoint '" << fromEndpointName
@ -617,7 +618,7 @@ void ApiListener::TryActivateZonesStageCallback(const ProcessResult& pr,
*
* @param relativePaths Required for later file operations in the callback. Provides the zone name plus path in a list.
*/
void ApiListener::AsyncTryActivateZonesStage(const std::vector<String>& relativePaths)
void ApiListener::AsyncTryActivateZonesStage(const std::vector<String>& relativePaths, const Shared<boost::mutex::scoped_lock>::Ptr& lock)
{
VERIFY(Application::GetArgC() >= 1);
@ -643,7 +644,10 @@ void ApiListener::AsyncTryActivateZonesStage(const std::vector<String>& relative
Process::Ptr process = new Process(Process::PrepareCommand(args));
process->SetTimeout(Application::GetReloadTimeout());
process->Run(std::bind(&TryActivateZonesStageCallback, _1, relativePaths));
process->Run([relativePaths, lock](const ProcessResult& pr) {
TryActivateZonesStageCallback(pr, relativePaths);
});
}
/**

View File

@ -200,7 +200,7 @@ private:
static void TryActivateZonesStageCallback(const ProcessResult& pr,
const std::vector<String>& relativePaths);
static void AsyncTryActivateZonesStage(const std::vector<String>& relativePaths);
static void AsyncTryActivateZonesStage(const std::vector<String>& relativePaths, const Shared<boost::mutex::scoped_lock>::Ptr& lock);
static String GetChecksum(const String& content);
static bool CheckConfigChange(const ConfigDirInformation& oldConfig, const ConfigDirInformation& newConfig);