From 3c43c104efe11e490278756c836178c43c06e119 Mon Sep 17 00:00:00 2001 From: Eric Cano <Eric.Cano@cern.ch> Date: Fri, 4 Jan 2019 10:55:18 +0100 Subject: [PATCH] Limited list of onwed objects in exception message. The full list is still available in a serie of log lines. --- objectstore/Agent.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/objectstore/Agent.cpp b/objectstore/Agent.cpp index f4b47ab0f7..6687b7ffaa 100644 --- a/objectstore/Agent.cpp +++ b/objectstore/Agent.cpp @@ -75,11 +75,41 @@ void cta::objectstore::Agent::removeAndUnregisterSelf(log::LogContext & lc) { checkPayloadWritable(); // Check that we are not empty if (!isEmpty()) { + // Log all owned objects by batches of 25. std::list<std::string> ownershipList = getOwnershipList(); + { + auto ownedObj = ownershipList.begin(); + size_t currentCount=0; + size_t startIndex=0; + size_t endIndex=0; + std::string currentObjs; + while (ownedObj != ownershipList.end()) { + if (currentObjs.size()) currentObjs+= " "; + currentObjs += *(ownedObj++); + endIndex++; + if (++currentCount >= 25 || ownedObj == ownershipList.end()) { + log::ScopedParamContainer params(lc); + params.add("objects", currentObjs) + .add("startIndex", startIndex) + .add("endIndex", endIndex - 1) + .add("totalObjects", ownershipList.size()); + lc.log(log::ERR, "In Agent::deleteAndUnregisterSelf: agent still owns objects. Here is a part of the list."); + startIndex = endIndex; + currentCount = 0; + currentObjs = ""; + } + } + } + // Prepare exception to be thrown. std::stringstream exSs; - exSs << "In Agent::deleteAndUnregisterSelf: agent still owns objects. Here's the list:"; + exSs << "In Agent::deleteAndUnregisterSelf: agent still owns objects. Here's the first few:"; + size_t count=0; for(auto i=ownershipList.begin(); i!=ownershipList.end(); i++) { exSs << " " << *i; + if (++count > 3) { + exSs << " [... trimmed at 3 of " << ownershipList.size() << "]"; + break; + } } throw AgentStillOwnsObjects(exSs.str()); } -- GitLab