From 198c19fe25b76781b04d2e2c3918252bb74d612d Mon Sep 17 00:00:00 2001 From: Eric Cano <Eric.Cano@cern.ch> Date: Tue, 7 Nov 2017 10:32:08 +0100 Subject: [PATCH] Added logging of removal of agent objects. --- objectstore/Agent.cpp | 9 +++++---- objectstore/Agent.hpp | 2 +- objectstore/BackendPopulator.cpp | 2 +- objectstore/GarbageCollector.cpp | 2 +- objectstore/GarbageCollectorTest.cpp | 12 ++++++------ objectstore/RootEntryTest.cpp | 9 ++++++--- .../cta-objectstore-collect-orphaned-object.cpp | 2 +- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/objectstore/Agent.cpp b/objectstore/Agent.cpp index 545f241b48..679ba05743 100644 --- a/objectstore/Agent.cpp +++ b/objectstore/Agent.cpp @@ -70,7 +70,7 @@ void cta::objectstore::Agent::insertAndRegisterSelf() { arLock.release(); } -void cta::objectstore::Agent::removeAndUnregisterSelf() { +void cta::objectstore::Agent::removeAndUnregisterSelf(log::LogContext & lc) { // Check that we own the proper lock checkPayloadWritable(); // Check that we are not empty @@ -85,13 +85,14 @@ void cta::objectstore::Agent::removeAndUnregisterSelf() { } // First delete ourselves remove(); + log::ScopedParamContainer params(lc); + params.add("agentObject", getAddressIfSet()); + lc.log(log::INFO, "In Agent::removeAndUnregisterSelf(): Removed agent object."); // Then we remove the dangling pointer about ourselves in the agent register. // We need to get hold of the agent register, which we suppose is available RootEntry re(m_objectStore); - ScopedSharedLock reLock(re); - re.fetch(); + re.fetchNoLock(); AgentRegister ar(re.getAgentRegisterAddress(), m_objectStore); - reLock.release(); // Then we should first create a pointer to our agent ScopedExclusiveLock arLock(ar); ar.fetch(); diff --git a/objectstore/Agent.hpp b/objectstore/Agent.hpp index e464990854..67b45820f3 100644 --- a/objectstore/Agent.hpp +++ b/objectstore/Agent.hpp @@ -52,7 +52,7 @@ public: void insertAndRegisterSelf(); - void removeAndUnregisterSelf(); + void removeAndUnregisterSelf(log::LogContext & lc); bool isEmpty(); diff --git a/objectstore/BackendPopulator.cpp b/objectstore/BackendPopulator.cpp index e1dd631f4d..95f5067d6b 100644 --- a/objectstore/BackendPopulator.cpp +++ b/objectstore/BackendPopulator.cpp @@ -62,7 +62,7 @@ BackendPopulator::~BackendPopulator() throw() { Agent agent(m_agentReference.getAgentAddress(), m_backend); cta::objectstore::ScopedExclusiveLock agl(agent); agent.fetch(); - agent.removeAndUnregisterSelf(); + agent.removeAndUnregisterSelf(m_lc); } catch (cta::exception::Exception & ex) { cta::log::ScopedParamContainer params(m_lc); params.add("errorMessage", ex.getMessageValue()); diff --git a/objectstore/GarbageCollector.cpp b/objectstore/GarbageCollector.cpp index eeeaa75830..7c7d1909e8 100644 --- a/objectstore/GarbageCollector.cpp +++ b/objectstore/GarbageCollector.cpp @@ -176,7 +176,7 @@ void GarbageCollector::cleanupDeadAgent(const std::string & address, log::LogCon agent.commit(); } // We now processed all the owned objects. We can delete the agent's entry - agent.removeAndUnregisterSelf(); + agent.removeAndUnregisterSelf(lc); lc.log(log::INFO, "In GarbageCollector::cleanupDeadAgent(): agent entry removed."); // We can remove the agent from our own ownership. m_ourAgentReference.removeFromOwnership(address, m_objectStore); diff --git a/objectstore/GarbageCollectorTest.cpp b/objectstore/GarbageCollectorTest.cpp index 48ebb1f25c..14ea0a465e 100644 --- a/objectstore/GarbageCollectorTest.cpp +++ b/objectstore/GarbageCollectorTest.cpp @@ -86,7 +86,7 @@ TEST(ObjectStore, GarbageCollectorBasicFuctionnality) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); @@ -145,7 +145,7 @@ TEST(ObjectStore, GarbageCollectorRegister) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); @@ -205,7 +205,7 @@ TEST(ObjectStore, GarbageCollectorArchiveQueue) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); @@ -265,7 +265,7 @@ TEST(ObjectStore, GarbageCollectorDriveRegister) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); @@ -443,7 +443,7 @@ TEST(ObjectStore, GarbageCollectorArchiveRequest) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); @@ -624,7 +624,7 @@ TEST(ObjectStore, GarbageCollectorRetrieveRequest) { // Unregister gc's agent cta::objectstore::ScopedExclusiveLock gcal(gcAgent); gcAgent.fetch(); - gcAgent.removeAndUnregisterSelf(); + gcAgent.removeAndUnregisterSelf(lc); // We should not be able to remove the agent register (as it should be empty) rel.lock(re); re.fetch(); diff --git a/objectstore/RootEntryTest.cpp b/objectstore/RootEntryTest.cpp index ba47ab8cdf..289f347784 100644 --- a/objectstore/RootEntryTest.cpp +++ b/objectstore/RootEntryTest.cpp @@ -76,6 +76,7 @@ TEST (ObjectStore, RootEntryArchiveQueues) { cta::objectstore::EntryLogSerDeser el("user0", "unittesthost", time(NULL)); cta::log::DummyLogger dl("dummyLogger"); + cta::log::LogContext lc(dl); cta::objectstore::AgentReference agr("UnitTests", dl); cta::objectstore::Agent ag(agr.getAgentAddress(), be); ag.initialize(); @@ -120,7 +121,7 @@ TEST (ObjectStore, RootEntryArchiveQueues) { } // Unregister the agent cta::objectstore::ScopedExclusiveLock agl(ag); - ag.removeAndUnregisterSelf(); + ag.removeAndUnregisterSelf(lc); // Delete the root entry cta::objectstore::RootEntry re(be); cta::objectstore::ScopedExclusiveLock lock(re); @@ -143,6 +144,7 @@ TEST (ObjectStore, RootEntryDriveRegister) { cta::objectstore::EntryLogSerDeser el("user0", "unittesthost", time(NULL)); cta::log::DummyLogger dl("dummyLogger"); + cta::log::LogContext lc(dl); cta::objectstore::AgentReference agr("UnitTests", dl); cta::objectstore::Agent ag(agr.getAgentAddress(), be); ag.initialize(); @@ -177,7 +179,7 @@ TEST (ObjectStore, RootEntryDriveRegister) { } // Unregister the agent cta::objectstore::ScopedExclusiveLock agl(ag); - ag.removeAndUnregisterSelf(); + ag.removeAndUnregisterSelf(lc); // Delete the root entry cta::objectstore::RootEntry re(be); cta::objectstore::ScopedExclusiveLock lock(re); @@ -247,6 +249,7 @@ TEST (ObjectStore, RootEntrySchedulerGlobalLock) { cta::objectstore::EntryLogSerDeser el("user0", "unittesthost", time(NULL)); cta::log::DummyLogger dl("dummyLogger"); + cta::log::LogContext lc(dl); cta::objectstore::AgentReference agr("UnitTests", dl); cta::objectstore::Agent ag(agr.getAgentAddress(), be); ag.initialize(); @@ -281,7 +284,7 @@ TEST (ObjectStore, RootEntrySchedulerGlobalLock) { } // Unregister the agent cta::objectstore::ScopedExclusiveLock agl(ag); - ag.removeAndUnregisterSelf(); + ag.removeAndUnregisterSelf(lc); // Delete the root entry cta::objectstore::RootEntry re(be); cta::objectstore::ScopedExclusiveLock lock(re); diff --git a/objectstore/cta-objectstore-collect-orphaned-object.cpp b/objectstore/cta-objectstore-collect-orphaned-object.cpp index 6b84c657e7..1509ccc740 100644 --- a/objectstore/cta-objectstore-collect-orphaned-object.cpp +++ b/objectstore/cta-objectstore-collect-orphaned-object.cpp @@ -129,7 +129,7 @@ int main(int argc, char ** argv) { break; } cta::objectstore::ScopedExclusiveLock agl(ag); - ag.removeAndUnregisterSelf(); + ag.removeAndUnregisterSelf(lc); } catch (std::exception & e) { std::cerr << "Failed to garbage collect object: " << std::endl << e.what() << std::endl; -- GitLab