Skip to content
Snippets Groups Projects
Commit bb652036 authored by Cedric CAFFY's avatar Cedric CAFFY Committed by Eric Cano
Browse files

Removed all the memory leak detected by valgrinding the unit tests

Refactored OStoreDB::RetrieveMount::batchSucceedRetrieveForRepack() method
parent 62cd0026
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,6 @@ class Agent: public ObjectOps<serializers::Agent, serializers::Agent_t> { ...@@ -45,7 +45,6 @@ class Agent: public ObjectOps<serializers::Agent, serializers::Agent_t> {
public: public:
CTA_GENERATE_EXCEPTION_CLASS(AgentStillOwnsObjects); CTA_GENERATE_EXCEPTION_CLASS(AgentStillOwnsObjects);
Agent(GenericObject & go); Agent(GenericObject & go);
Agent(const std::string & name, Backend & os); Agent(const std::string & name, Backend & os);
void initialize(); void initialize();
......
...@@ -16,4 +16,4 @@ ...@@ -16,4 +16,4 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "AgentWatchdog.hpp" #include "AgentWatchdog.hpp"
\ No newline at end of file
...@@ -36,6 +36,7 @@ namespace unitTests { ...@@ -36,6 +36,7 @@ namespace unitTests {
void fillRetrieveRequests( void fillRetrieveRequests(
typename cta::objectstore::ContainerAlgorithms<cta::objectstore::RetrieveQueue,cta::objectstore::RetrieveQueueToTransfer>::InsertedElement::list &requests, typename cta::objectstore::ContainerAlgorithms<cta::objectstore::RetrieveQueue,cta::objectstore::RetrieveQueueToTransfer>::InsertedElement::list &requests,
std::list<std::unique_ptr<cta::objectstore::RetrieveRequest> >& requestPtrs, //List to avoid memory leak on ArchiveQueueAlgorithms test
cta::objectstore::BackendVFS &be, cta::objectstore::BackendVFS &be,
cta::objectstore::AgentReference &agentRef) cta::objectstore::AgentReference &agentRef)
{ {
...@@ -71,8 +72,9 @@ void fillRetrieveRequests( ...@@ -71,8 +72,9 @@ void fillRetrieveRequests(
rqc.mountPolicy.maxDrivesAllowed = 1; rqc.mountPolicy.maxDrivesAllowed = 1;
rqc.mountPolicy.retrieveMinRequestAge = 1; rqc.mountPolicy.retrieveMinRequestAge = 1;
rqc.mountPolicy.retrievePriority = 1; rqc.mountPolicy.retrievePriority = 1;
requestPtrs.emplace_back(new cta::objectstore::RetrieveRequest(rrAddr, be));
requests.emplace_back(ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement{ requests.emplace_back(ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement{
new RetrieveRequest(rrAddr, be), 1, i, 667, mp, serializers::RetrieveJobStatus::RJS_ToTransfer requestPtrs.back().get(), 1, i, 667, mp, serializers::RetrieveJobStatus::RJS_ToTransfer
}); });
auto &rr = *requests.back().retrieveRequest; auto &rr = *requests.back().retrieveRequest;
rr.initialize(); rr.initialize();
...@@ -185,8 +187,9 @@ TEST(ObjectStore, RetrieveQueueAlgorithms) { ...@@ -185,8 +187,9 @@ TEST(ObjectStore, RetrieveQueueAlgorithms) {
rel.release(); rel.release();
agent.initialize(); agent.initialize();
agent.insertAndRegisterSelf(lc); agent.insertAndRegisterSelf(lc);
std::list<std::unique_ptr<RetrieveRequest> > requestsPtrs;
ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement::list requests; ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement::list requests;
fillRetrieveRequests(requests, be, agentRef); fillRetrieveRequests(requests, requestsPtrs, be, agentRef); //memory leak here
{ {
// Second agent to test referenceAndSwitchOwnershipIfNecessary // Second agent to test referenceAndSwitchOwnershipIfNecessary
...@@ -205,7 +208,8 @@ TEST(ObjectStore, RetrieveQueueAlgorithms) { ...@@ -205,7 +208,8 @@ TEST(ObjectStore, RetrieveQueueAlgorithms) {
agent2.initialize(); agent2.initialize();
agent2.insertAndRegisterSelf(lc); agent2.insertAndRegisterSelf(lc);
ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement::list requests2; ContainerAlgorithms<RetrieveQueue,RetrieveQueueToTransfer>::InsertedElement::list requests2;
fillRetrieveRequests(requests2, be2, agentRef2); std::list<std::unique_ptr<RetrieveRequest> > requestsPtrs2;
fillRetrieveRequests(requests2, requestsPtrs2,be2, agentRef2);
auto a1 = agentRef2.getAgentAddress(); auto a1 = agentRef2.getAgentAddress();
auto a2 = agentRef2.getAgentAddress(); auto a2 = agentRef2.getAgentAddress();
......
...@@ -40,6 +40,14 @@ GarbageCollector::GarbageCollector(Backend & os, AgentReference & agentReference ...@@ -40,6 +40,14 @@ GarbageCollector::GarbageCollector(Backend & os, AgentReference & agentReference
m_agentRegister.fetch(); m_agentRegister.fetch();
} }
GarbageCollector::~GarbageCollector(){
//Normally, the Garbage collector is never destroyed in production
//this destructor is here to avoid memory leaks on unit tests
for(auto &kv : m_watchedAgents){
delete kv.second;
}
}
void GarbageCollector::runOnePass(log::LogContext & lc) { void GarbageCollector::runOnePass(log::LogContext & lc) {
trimGoneTargets(lc); trimGoneTargets(lc);
acquireTargets(lc); acquireTargets(lc);
......
...@@ -41,7 +41,7 @@ class RetrieveRequest; ...@@ -41,7 +41,7 @@ class RetrieveRequest;
class GarbageCollector { class GarbageCollector {
public: public:
GarbageCollector(Backend & os, AgentReference & agentReference, catalogue::Catalogue & catalogue); GarbageCollector(Backend & os, AgentReference & agentReference, catalogue::Catalogue & catalogue);
~GarbageCollector();
void runOnePass(log::LogContext & lc); void runOnePass(log::LogContext & lc);
void acquireTargets(log::LogContext & lc); void acquireTargets(log::LogContext & lc);
......
...@@ -720,7 +720,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_failure) { ...@@ -720,7 +720,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_failure) {
scheduler.queueRetrieve("disk_instance", request, lc); scheduler.queueRetrieve("disk_instance", request, lc);
scheduler.waitSchedulerDbSubthreadsComplete(); scheduler.waitSchedulerDbSubthreadsComplete();
} }
// Try mounting the tape twice // Try mounting the tape twice
for(int mountPass = 0; mountPass < 2; ++mountPass) for(int mountPass = 0; mountPass < 2; ++mountPass)
{ {
...@@ -800,7 +800,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_failure) { ...@@ -800,7 +800,7 @@ TEST_P(SchedulerTest, archive_and_retrieve_failure) {
getSchedulerDB().replaceAgent(new objectstore::AgentReference("OStoreDBFactory2", dl)); getSchedulerDB().replaceAgent(new objectstore::AgentReference("OStoreDBFactory2", dl));
} // end of retries } // end of retries
} // end of pass } // end of pass
{ {
// We expect the retrieve queue to be empty // We expect the retrieve queue to be empty
auto rqsts = scheduler.getPendingRetrieveJobs(lc); auto rqsts = scheduler.getPendingRetrieveJobs(lc);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment