From ee6c61df18f46ff48885dc297cf49bfa7ddf4a1b Mon Sep 17 00:00:00 2001 From: Michael Davis <michael.davis@cern.ch> Date: Fri, 17 Aug 2018 17:03:33 +0200 Subject: [PATCH] [os-generic-queues] Implements Retrieve referenceAndSwitchOwnershipIfNecessary() --- objectstore/Algorithms.hpp | 10 ++++++---- objectstore/AlgorithmsTest.cpp | 8 ++++++++ objectstore/RetrieveQueueAlgorithms.cpp | 21 +++++++-------------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/objectstore/Algorithms.hpp b/objectstore/Algorithms.hpp index e1ac501d02..8fbee087ab 100644 --- a/objectstore/Algorithms.hpp +++ b/objectstore/Algorithms.hpp @@ -205,10 +205,12 @@ public: } } - /** Reference objects in the container if needed and then switch their ownership (if needed). Objects - * are expected to be owned by agent, and not listed in the container but situations might vary. - * This function is typically used by the garbage collector. We do noe take care of dereferencing - * the object from the caller. + /** + * Reference objects in the container if needed and then switch their ownership (if needed). + * + * Objects are expected to be owned by an agent and not listed in the container, but situations + * might vary. This function is typically used by the garbage collector. We do not take care of + * dereferencing the object from the caller. */ void referenceAndSwitchOwnershipIfNecessary(const typename ContainerTraits<C>::ContainerIdentifier & contId, typename ContainerTraits<C>::ContainerAddress & previousOwnerAddress, diff --git a/objectstore/AlgorithmsTest.cpp b/objectstore/AlgorithmsTest.cpp index 27001f5dd9..a28094e218 100644 --- a/objectstore/AlgorithmsTest.cpp +++ b/objectstore/AlgorithmsTest.cpp @@ -177,7 +177,15 @@ TEST(ObjectStore, RetrieveQueueAlgorithms) { ContainerAlgorithms<RetrieveQueue> retrieveAlgos(be, agentRef); try { ASSERT_EQ(requests.size(), 10); + +#if 1 + auto a1 = agentRef.getAgentAddress(); + auto a2 = agentRef.getAgentAddress(); + retrieveAlgos.referenceAndSwitchOwnershipIfNecessary("VID", a1, a2, requests, lc); +#else retrieveAlgos.referenceAndSwitchOwnership("VID", requests, lc); +#endif + // Now get the requests back ContainerTraits<RetrieveQueue>::PopCriteria popCriteria; popCriteria.bytes = std::numeric_limits<decltype(popCriteria.bytes)>::max(); diff --git a/objectstore/RetrieveQueueAlgorithms.cpp b/objectstore/RetrieveQueueAlgorithms.cpp index 64be8fdd77..254dc11761 100644 --- a/objectstore/RetrieveQueueAlgorithms.cpp +++ b/objectstore/RetrieveQueueAlgorithms.cpp @@ -149,23 +149,16 @@ addReferencesAndCommit(Container &cont, InsertedElement::list &elemMemCont, Agen } template<> -void ContainerTraits<RetrieveQueue>::addReferencesIfNecessaryAndCommit(Container& cont, - InsertedElement::list& elemMemCont, AgentReference& agentRef, log::LogContext& lc) +void ContainerTraits<RetrieveQueue>:: +addReferencesIfNecessaryAndCommit(Container& cont, InsertedElement::list& elemMemCont, + AgentReference& agentRef, log::LogContext& lc) { - throw std::runtime_error("ContainerTraits<RetrieveQueue>::addReferencesIfNecessaryAndCommit(): Not implemented"); -#if 0 - std::list<ArchiveQueue::JobToAdd> jobsToAdd; - for (auto & e: elemMemCont) { - ElementDescriptor jd; - jd.copyNb = e.copyNb; - jd.tapePool = cont.getTapePool(); - jd.owner = cont.getAddressIfSet(); - ArchiveRequest & ar = *e.archiveRequest; - jobsToAdd.push_back({jd, ar.getAddressIfSet(), e.archiveFile.archiveFileID, e.archiveFile.fileSize, - e.mountPolicy, time(nullptr)}); + std::list<RetrieveQueue::JobToAdd> jobsToAdd; + for (auto &e : elemMemCont) { + RetrieveRequest &rr = *e.retrieveRequest; + jobsToAdd.push_back({e.copyNb, e.fSeq, rr.getAddressIfSet(), e.filesize, e.policy, ::time(nullptr)}); } cont.addJobsIfNecessaryAndCommit(jobsToAdd, agentRef, lc); -#endif } template<> -- GitLab