Commit 8c4da88f authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[objectstore] Corrected the RepackRequest::garbageCollect() method. It now...

[objectstore] Corrected the RepackRequest::garbageCollect() method. It now changes the owner of the RepackRequest
parent ecff59b2
......@@ -946,6 +946,7 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
agent.initialize();
agent.setTimeout_us(0);
agent.insertAndRegisterSelf(lc);
std::string repackRequestAddress;
{
// Create an agent to be garbage collected
cta::objectstore::AgentReference agentReferenceRepackRequest("AgentReferenceRepackRequest", dl);
......@@ -959,9 +960,9 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
re.fetch();
//Create the RepackRequest
std::string repackRequestAddr = agentReferenceRepackRequest.nextId("RepackRequest");
agentReferenceRepackRequest.addToOwnership(repackRequestAddr, be);
cta::objectstore::RepackRequest repackRequest(repackRequestAddr,be);
repackRequestAddress = agentReferenceRepackRequest.nextId("RepackRequest");
agentReferenceRepackRequest.addToOwnership(repackRequestAddress, be);
cta::objectstore::RepackRequest repackRequest(repackRequestAddress,be);
repackRequest.initialize();
repackRequest.setStatus(cta::common::dataStructures::RepackInfo::Status::Running);
repackRequest.setVid("VIDTest");
......@@ -974,12 +975,14 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
}
cta::log::StringLogger strLogger("dummy", "dummy", cta::log::DEBUG);
cta::log::LogContext lc2(strLogger);
std::string agentGarbageCollectingRepackRequestAddress;
{
// Now we garbage collect the RepackRequest
// Create the garbage collector and run it once.
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector", strLogger);
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
agentGarbageCollectingRepackRequestAddress = gcAgentRef.getAgentAddress();
cta::objectstore::Agent gcAgent(agentGarbageCollectingRepackRequestAddress, be);
gcAgent.initialize();
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf(lc2);
......@@ -989,7 +992,7 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
}
}
{
//The request should not be requeued in the ToExpand as it has finished to expand
//The request should not be requeued in the ToExpand queue as it has finished to expand and is running
cta::objectstore::RootEntry re(be);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
......@@ -1000,7 +1003,7 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
ASSERT_EQ(0,rq.getRequestsSummary().requests);
}
{
//The request should not be requeued in the ToExpand as it has not finished to expand
//The request should not be requeued in the Pending queue as it is running
cta::objectstore::RootEntry re(be);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
......@@ -1010,6 +1013,12 @@ TEST(ObjectStore, GarbageCollectorRepackRequestRunningExpandFinished) {
rq.fetch();
ASSERT_EQ(0,rq.getRequestsSummary().requests);
}
{
//Check that the owner of the repack request has been updated and is equal to the garbageCollector's agent
cta::objectstore::RepackRequest repackRequest(repackRequestAddress,be);
repackRequest.fetchNoLock();
ASSERT_EQ(agentGarbageCollectingRepackRequestAddress,repackRequest.getOwner());
}
//Check the logs contains the failed to requeue message
std::string logToCheck = strLogger.getLog();
logToCheck += "";
......
......@@ -705,6 +705,8 @@ void RepackRequest::garbageCollect(const std::string& presumedOwner, AgentRefere
log::LogContext& lc, cta::catalogue::Catalogue& catalogue) {
//Let's requeue the RepackRequest if its status is ToExpand or Pending
agentReference.addToOwnership(this->getAddressIfSet(), m_objectStore);
//The owner of this RepackRequest is the agentReference
setOwner(agentReference.getAgentAddress());
cta::utils::Timer t;
RepackQueue rq(m_objectStore);
ScopedExclusiveLock rql;
......@@ -712,6 +714,7 @@ void RepackRequest::garbageCollect(const std::string& presumedOwner, AgentRefere
Helpers::getLockedAndFetchedRepackQueue(rq, rql, agentReference, this->getInfo().getQueueType(), lc);
} catch(const cta::exception::Exception &e){
lc.log(log::INFO,"In RepackRequest::garbageCollect(): failed to requeue the RepackRequest (leaving it as it is) : "+e.getMessage().str());
commit();
return;
}
double queueLockFetchTime = t.secs(utils::Timer::resetCounter);
......@@ -732,6 +735,7 @@ void RepackRequest::garbageCollect(const std::string& presumedOwner, AgentRefere
} catch(const cta::exception::Exception &e){
lc.log(log::INFO,"In RepackRequest::garbageCollect() failed to requeue the RepackRequest. Leaving it as it is.");
}
commit();
}
//------------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment