Skip to content
Snippets Groups Projects
Commit c87c771b authored by Eric Cano's avatar Eric Cano
Browse files

Added garbage collection for TapePool.

parent 918e8f45
Branches
Tags
No related merge requests found
......@@ -20,10 +20,10 @@
#include "BackendVFS.hpp"
#include "common/exception/Exception.hpp"
#include "GarbageCollector.hpp"
//#include "FIFO.hpp"
#include "RootEntry.hpp"
#include "Agent.hpp"
#include "AgentRegister.hpp"
#include "RootEntry.hpp"
#include "TapePool.hpp"
namespace unitTests {
......@@ -122,6 +122,7 @@ TEST(GarbageCollector, AgentRegister) {
gc.runOnePass();
gc.runOnePass();
}
ASSERT_FALSE(be.exists(arName));
// Unregister gc's agent
cta::objectstore::ScopedExclusiveLock gcal(gcAgent);
gcAgent.removeAndUnregisterSelf();
......@@ -132,4 +133,62 @@ TEST(GarbageCollector, AgentRegister) {
ASSERT_NO_THROW(re.removeIfEmpty());
}
TEST(GarbageCollector, TapePool) {
// Here we check that can successfully call agentRegister's garbage collector
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
re.insert();
// Create the agent register
cta::objectstore::CreationLog cl(99, "dummyUser", 99, "dummyGroup",
"unittesthost", time(NULL), "Creation of unit test agent register");
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, cl);
rel.release();
// Create an agent and add and agent register to it as an owned object
cta::objectstore::Agent agA(be);
agA.initialize();
agA.generateName("unitTestAgentA");
agA.setTimeout_us(0);
agA.insertAndRegisterSelf();
// Create a new agent register, owned by agA (by hand as it is not an usual
// situation)
std::string tpName;
{
tpName = agA.nextId("TapePool");
cta::objectstore::TapePool tp(tpName, be);
tp.initialize("SomeTP");
tp.setOwner(agA.getAddressIfSet());
cta::objectstore::ScopedExclusiveLock agl(agA);
agA.fetch();
agA.addToOwnership(tpName);
agA.commit();
tp.insert();
}
// Create the garbage colletor and run it twice.
cta::objectstore::Agent gcAgent(be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
cta::objectstore::GarbageCollector gc(be, gcAgent);
gc.runOnePass();
gc.runOnePass();
}
ASSERT_FALSE(be.exists(tpName));
// Unregister gc's agent
cta::objectstore::ScopedExclusiveLock gcal(gcAgent);
gcAgent.removeAndUnregisterSelf();
// We should not be able to remove the agent register (as it should be empty)
rel.lock(re);
re.fetch();
ASSERT_NO_THROW(re.removeAgentRegisterAndCommit());
ASSERT_NO_THROW(re.removeIfEmpty());
}
}
......@@ -18,6 +18,7 @@
#include "GenericObject.hpp"
#include "AgentRegister.hpp"
#include "TapePool.hpp"
namespace cta { namespace objectstore {
......@@ -70,8 +71,12 @@ void GenericObject::garbageCollect(ScopedExclusiveLock& lock) {
AgentRegister ar(*this);
lock.transfer(ar);
ar.garbageCollect();
break;
}
} break;
case serializers::TapePool_t: {
TapePool tp(*this);
lock.transfer(tp);
tp.garbageCollect();
} break;
default: {
std::stringstream err;
err << "In GenericObject::garbageCollect, unsupported type: "
......
......@@ -17,10 +17,20 @@
*/
#include "TapePool.hpp"
#include "GenericObject.hpp"
cta::objectstore::TapePool::TapePool(const std::string& address, Backend& os):
ObjectOps<serializers::TapePool>(os, address) { }
cta::objectstore::TapePool::TapePool(GenericObject& go):
ObjectOps<serializers::TapePool>(go.objectStore()) {
// Here we transplant the generic object into the new object
go.transplantHeader(*this);
// And interpret the header.
getPayloadFromHeader();
}
void cta::objectstore::TapePool::initialize(const std::string& name) {
// Setup underlying object
ObjectOps<serializers::TapePool>::initialize();
......@@ -44,6 +54,15 @@ bool cta::objectstore::TapePool::isEmpty() {
return true;
}
void cta::objectstore::TapePool::garbageCollect() {
checkPayloadWritable();
if (!isEmpty()) {
throw (NotEmpty("Trying to garbage collect a non-empty AgentRegister: internal error"));
}
remove();
}
void cta::objectstore::TapePool::setName(const std::string& name) {
checkPayloadWritable();
m_payload.set_name(name);
......
......@@ -24,11 +24,16 @@
#include "objectstore/cta.pb.h"
namespace cta { namespace objectstore {
class GenericObject;
class TapePool: public ObjectOps<serializers::TapePool> {
public:
// Constructor
TapePool(const std::string & address, Backend & os);
// Upgrader form generic object
TapePool(GenericObject & go);
// In memory initialiser
void initialize(const std::string & name);
......@@ -39,6 +44,10 @@ public:
// Check that the tape pool is empty (of both tapes and jobs)
bool isEmpty();
CTA_GENERATE_EXCEPTION_CLASS(NotEmpty);
// Garbage collection
void garbageCollect();
};
}}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment