IBM Mgmt console lock algorithm improvement

This commit optimizes the release lock code and adds some traces to give
more data for lock conflict scenarios

Tested by:
 1. With dual client connected, verified the conflicts are returned
 2. Tested releaseLock usecase

Signed-off-by: Sunitha Harish <sunithaharish04@gmail.com>
Change-Id: I3cf99aaa5cc7c2967ae8dbc9c76c9f7378ecebdd
diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp
index 5220a5d..7cd8037 100644
--- a/include/ibm/locks.hpp
+++ b/include/ibm/locks.hpp
@@ -220,23 +220,20 @@
 inline RcReleaseLockApi Lock::releaseLock(const ListOfTransactionIds& p,
                                           const SessionFlags& ids)
 {
-
     bool status = validateRids(p);
 
     if (!status)
     {
         // Validation of rids failed
-        BMCWEB_LOG_DEBUG << "Not a Valid request id";
+        BMCWEB_LOG_ERROR << "releaseLock: Contains invalid request id";
         return std::make_pair(false, status);
     }
     // Validation passed, check if all the locks are owned by the
     // requesting HMC
     auto status2 = isItMyLock(p, ids);
-    if (status2.first)
+    if (!status2.first)
     {
-        // The current hmc owns all the locks, so we can release
-        // them
-        releaseLock(p);
+        return std::make_pair(false, status2);
     }
     return std::make_pair(true, status2);
 }
@@ -276,25 +273,6 @@
     return std::make_pair(false, conflict);
 }
 
-inline void Lock::releaseLock(const ListOfTransactionIds& refRids)
-{
-    for (const auto& id : refRids)
-    {
-        if (lockTable.erase(id) != 0U)
-        {
-            BMCWEB_LOG_DEBUG << "Removing the locks with transaction ID : "
-                             << id;
-        }
-
-        else
-        {
-            BMCWEB_LOG_DEBUG << "Removing the locks from the lock table "
-                                "failed, transaction ID: "
-                             << id;
-        }
-    }
-}
-
 inline void Lock::releaseLock(const std::string& sessionId)
 {
     if (!lockTable.empty())
@@ -339,6 +317,18 @@
         {
             // It is owned by the currently request hmc
             BMCWEB_LOG_DEBUG << "Lock is owned  by the current hmc";
+            // remove the lock
+            if (lockTable.erase(id) != 0U)
+            {
+                BMCWEB_LOG_DEBUG << "Removing the locks with transaction ID : "
+                                 << id;
+            }
+            else
+            {
+                BMCWEB_LOG_ERROR << "Removing the locks from the lock table "
+                                    "failed, transaction ID: "
+                                 << id;
+            }
         }
         else
         {
@@ -362,7 +352,8 @@
         }
         else
         {
-            BMCWEB_LOG_DEBUG << "At least 1 inValid Request id";
+            BMCWEB_LOG_ERROR << "validateRids: At least 1 inValid Request id: "
+                             << id;
             return false;
         }
     }
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index e51f64a..0a8b146 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -488,7 +488,7 @@
         }
         if (validityStatus.first && (validityStatus.second == 1))
         {
-            BMCWEB_LOG_DEBUG << "There is a conflict within itself";
+            BMCWEB_LOG_ERROR << "There is a conflict within itself";
             asyncResp->res.result(boost::beast::http::status::conflict);
             return;
         }
@@ -529,7 +529,7 @@
         }
 
         returnJson["SegmentFlags"] = myarray;
-
+        BMCWEB_LOG_ERROR << "Conflicting lock record: " << returnJson;
         asyncResp->res.jsonValue["Record"] = returnJson;
         return;
     }
@@ -563,6 +563,7 @@
     if (!varReleaselock.first)
     {
         // validation Failed
+        BMCWEB_LOG_ERROR << "handleReleaseLockAPI: validation failed";
         asyncResp->res.result(boost::beast::http::status::bad_request);
         return;
     }
@@ -597,6 +598,7 @@
     }
 
     returnJson["SegmentFlags"] = myArray;
+    BMCWEB_LOG_DEBUG << "handleReleaseLockAPI: lockrecord: " << returnJson;
     asyncResp->res.jsonValue["Record"] = returnJson;
 }