qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kgiu...@apache.org
Subject svn commit: r1416037 - in /qpid/trunk/qpid/cpp/src/qpid/agent: ManagementAgentImpl.cpp ManagementAgentImpl.h
Date Sat, 01 Dec 2012 18:24:49 GMT
Author: kgiusti
Date: Sat Dec  1 18:24:48 2012
New Revision: 1416037

URL: http://svn.apache.org/viewvc?rev=1416037&view=rev
Log:
QPID-4485: hold agentLock and check for dups when adding new mgmt objects

Modified:
    qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
    qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h

Modified: qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp?rev=1416037&r1=1416036&r2=1416037&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.cpp Sat Dec  1 18:24:48 2012
@@ -654,7 +654,10 @@ void ManagementAgentImpl::invokeMethodRe
 
 void ManagementAgentImpl::handleGetQuery(const string& body, const string& cid, const
string& rte, const string& rtk)
 {
-    moveNewObjectsLH();
+    {
+        sys::Mutex::ScopedLock lock(agentLock);
+        moveNewObjectsLH(lock);
+    }
 
     Variant::Map inMap;
     Variant::Map::const_iterator i;
@@ -985,14 +988,37 @@ ManagementAgentImpl::PackageMap::iterato
     return result.first;
 }
 
-void ManagementAgentImpl::moveNewObjectsLH()
+// note well: caller must hold agentLock when calling this!
+void ManagementAgentImpl::moveNewObjectsLH(const sys::Mutex::ScopedLock& /*agentLock*/)
 {
     sys::Mutex::ScopedLock lock(addLock);
-    for (ObjectMap::iterator iter = newManagementObjects.begin();
-         iter != newManagementObjects.end();
-         iter++)
-        managementObjects[iter->first] = iter->second;
-    newManagementObjects.clear();
+    ObjectMap::iterator newObj = newManagementObjects.begin();
+    while (newObj != newManagementObjects.end()) {
+        // before adding a new mgmt object, check for duplicates:
+        ObjectMap::iterator oldObj = managementObjects.find(newObj->first);
+        if (oldObj == managementObjects.end()) {
+            managementObjects[newObj->first] = newObj->second;
+            newManagementObjects.erase(newObj++);  // post inc iterator safe!
+        } else {
+            // object exists with same object id.  This may be legit, for example, when a
+            // recently deleted object is re-added before the mgmt poll runs.
+            if (newObj->second->isDeleted()) {
+                // @TODO fixme: we missed an add-delete for the new object
+                QPID_LOG(warning, "Mgmt Object deleted before update sent, oid=" <<
newObj->first);
+                newManagementObjects.erase(newObj++);  // post inc iterator safe!
+            } else if (oldObj->second->isDeleted()) {
+                // skip adding newObj, try again later once oldObj has been cleaned up by
poll
+                ++newObj;
+            } else {
+                // real bad - two objects exist with same OID.  This is a bug in the application
+                QPID_LOG(error, "Detected two Mgmt Objects using the same object id! oid="
<< newObj->first
+                         << ", this is bad!");
+                // what to do here?  Can't erase an active obj - owner has a pointer to it.
+                // for now I punt.  Maybe the flood of log messages will get someone's attention
:P
+                ++newObj;
+            }
+        }
+    }
 }
 
 void ManagementAgentImpl::addClassLocal(uint8_t               classKind,
@@ -1060,7 +1086,7 @@ void ManagementAgentImpl::periodicProces
         if (!connected)
             return;
 
-        moveNewObjectsLH();
+        moveNewObjectsLH(lock);
 
         //
         //  Clear the been-here flag on all objects in the map.

Modified: qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h?rev=1416037&r1=1416036&r2=1416037&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/agent/ManagementAgentImpl.h Sat Dec  1 18:24:48 2012
@@ -261,7 +261,7 @@ class ManagementAgentImpl : public Manag
     void storeData(bool requested=false);
     void retrieveData(std::string& vendor, std::string& product, std::string&
inst);
     PackageMap::iterator findOrAddPackage(const std::string& name);
-    void moveNewObjectsLH();
+    void moveNewObjectsLH(const sys::Mutex::ScopedLock& agentLock);
     void addClassLocal (uint8_t               classKind,
                         PackageMap::iterator  pIter,
                         const std::string&    className,



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message