Don't allow to modify/create/delete an object concurrently

This commit is contained in:
Yonas Habteab 2024-03-11 12:34:14 +01:00 committed by Alexander A. Klimov
parent 1b35fe1393
commit 80e8c166ed
3 changed files with 12 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include "remote/jsonrpcconnection.hpp" #include "remote/jsonrpcconnection.hpp"
#include "remote/filterutility.hpp" #include "remote/filterutility.hpp"
#include "remote/apiaction.hpp" #include "remote/apiaction.hpp"
#include "remote/configobjectslock.hpp"
#include "remote/zone.hpp" #include "remote/zone.hpp"
#include "base/configtype.hpp" #include "base/configtype.hpp"
#include <set> #include <set>
@ -116,6 +117,9 @@ bool CreateObjectHandler::HandleRequest(
return true; return true;
} }
// Lock the object name of the given type to prevent from being created concurrently.
ObjectNameLock objectNameLock(type, name);
if (!ConfigObjectUtility::CreateObject(type, name, config, errors, diagnosticInformation)) { if (!ConfigObjectUtility::CreateObject(type, name, config, errors, diagnosticInformation)) {
result1->Set("errors", errors); result1->Set("errors", errors);
result1->Set("code", 500); result1->Set("code", 500);

View File

@ -5,6 +5,7 @@
#include "remote/httputility.hpp" #include "remote/httputility.hpp"
#include "remote/filterutility.hpp" #include "remote/filterutility.hpp"
#include "remote/apiaction.hpp" #include "remote/apiaction.hpp"
#include "remote/configobjectslock.hpp"
#include "config/configitem.hpp" #include "config/configitem.hpp"
#include "base/exception.hpp" #include "base/exception.hpp"
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
@ -76,6 +77,9 @@ bool DeleteObjectHandler::HandleRequest(
Array::Ptr errors = new Array(); Array::Ptr errors = new Array();
Array::Ptr diagnosticInformation = new Array(); Array::Ptr diagnosticInformation = new Array();
// Lock the object name of the given type to prevent from being modified/deleted concurrently.
ObjectNameLock objectNameLock(type, obj->GetName());
if (!ConfigObjectUtility::DeleteObject(obj, cascade, errors, diagnosticInformation)) { if (!ConfigObjectUtility::DeleteObject(obj, cascade, errors, diagnosticInformation)) {
code = 500; code = 500;
status = "Object could not be deleted."; status = "Object could not be deleted.";

View File

@ -4,6 +4,7 @@
#include "remote/httputility.hpp" #include "remote/httputility.hpp"
#include "remote/filterutility.hpp" #include "remote/filterutility.hpp"
#include "remote/apiaction.hpp" #include "remote/apiaction.hpp"
#include "remote/configobjectslock.hpp"
#include "base/exception.hpp" #include "base/exception.hpp"
#include <boost/algorithm/string/case_conv.hpp> #include <boost/algorithm/string/case_conv.hpp>
#include <set> #include <set>
@ -87,6 +88,9 @@ bool ModifyObjectHandler::HandleRequest(
String key; String key;
// Lock the object name of the given type to prevent from being modified/deleted concurrently.
ObjectNameLock objectNameLock(type, obj->GetName());
try { try {
if (attrs) { if (attrs) {
ObjectLock olock(attrs); ObjectLock olock(attrs);