Commit 390ccab7 authored by Eric Cano's avatar Eric Cano
Browse files

Split the Agent class into AgentReference and Agent.

Agent becomes a usual class, like any other in the object store.
Object name generation (agent's and others) is now handled in the separate AgentReference.
The previous situation created race conditions.
parent 643d26b3
......@@ -24,16 +24,10 @@
#include "ProtocolBuffersAlgorithms.hpp"
#include <string>
#include <sstream>
#include <iomanip>
#include <sys/syscall.h>
#include <ctime>
#include <cxxabi.h>
#include <unistd.h>
#include <json-c/json.h>
cta::objectstore::Agent::Agent(Backend & os):
ObjectOps<serializers::Agent, serializers::Agent_t>(os), m_nextId(0) {}
cta::objectstore::Agent::Agent(GenericObject& go):
ObjectOps<serializers::Agent, serializers::Agent_t>(go.objectStore()) {
// Here we transplant the generic object into the new object
......@@ -53,28 +47,6 @@ void cta::objectstore::Agent::initialize() {
m_payloadInterpreted = true;
}
void cta::objectstore::Agent::generateName(const std::string & typeName) {
std::stringstream aid;
// Get time
time_t now = time(0);
struct tm localNow;
localtime_r(&now, &localNow);
// Get hostname
char host[200];
cta::exception::Errnum::throwOnMinusOne(gethostname(host, sizeof(host)),
"In AgentId::AgentId: failed to gethostname");
// gettid is a safe system call (never fails)
aid << typeName << "-" << host << "-" << syscall(SYS_gettid) << "-"
<< 1900 + localNow.tm_year
<< std::setfill('0') << std::setw(2)
<< 1 + localNow.tm_mon
<< std::setw(2) << localNow.tm_mday << "-"
<< std::setw(2) << localNow.tm_hour << ":"
<< std::setw(2) << localNow.tm_min << ":"
<< std::setw(2) << localNow.tm_sec;
setAddress(aid.str());
}
void cta::objectstore::Agent::insertAndRegisterSelf() {
// We suppose initialize was already called, and that the agent name
// is set.
......@@ -149,12 +121,6 @@ bool cta::objectstore::Agent::isEmpty() {
m_creationDone = true;
}*/
std::string cta::objectstore::Agent::nextId(const std::string & childType) {
std::stringstream id;
id << childType << "-" << getAddressIfSet() << "-" << m_nextId++;
return id.str();
}
void cta::objectstore::Agent::addToOwnership(std::string name) {
checkPayloadWritable();
std::string * owned = m_payload.mutable_ownedobjects()->Add();
......
......@@ -40,17 +40,12 @@ class GenericObject;
class Agent: public ObjectOps<serializers::Agent, serializers::Agent_t> {
public:
CTA_GENERATE_EXCEPTION_CLASS(AgentStillOwnsObjects);
Agent(Backend & os);
Agent(GenericObject & go);
Agent(const std::string & name, Backend & os);
void initialize();
void generateName(const std::string & typeName);
std::string nextId(const std::string & childType);
void insertAndRegisterSelf();
void removeAndUnregisterSelf();
......
......@@ -25,18 +25,18 @@ namespace cta { namespace objectstore {
//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
BackendPopulator::BackendPopulator(cta::objectstore::Backend & be): m_backend(be), m_agent(m_backend) {
BackendPopulator::BackendPopulator(cta::objectstore::Backend & be): m_backend(be), m_agentReference("OStoreDBFactory") {
cta::objectstore::RootEntry re(m_backend);
cta::objectstore::ScopedExclusiveLock rel(re);
re.fetch();
m_agent.generateName("OStoreDBFactory");
m_agent.initialize();
Agent agent(m_agentReference.getAgentAddress(), m_backend);
agent.initialize();
cta::objectstore::EntryLogSerDeser cl("user0", "systemhost", time(NULL));
re.addOrGetAgentRegisterPointerAndCommit(m_agent,cl);
re.addOrGetAgentRegisterPointerAndCommit(m_agentReference, cl);
rel.release();
m_agent.insertAndRegisterSelf();
agent.insertAndRegisterSelf();
rel.lock(re);
re.addOrGetDriveRegisterPointerAndCommit(m_agent, cl);
re.addOrGetDriveRegisterPointerAndCommit(m_agentReference, cl);
rel.release();
}
......@@ -44,16 +44,17 @@ BackendPopulator::BackendPopulator(cta::objectstore::Backend & be): m_backend(be
// Destructor
//------------------------------------------------------------------------------
BackendPopulator::~BackendPopulator() throw() {
cta::objectstore::ScopedExclusiveLock agl(m_agent);
m_agent.fetch();
m_agent.removeAndUnregisterSelf();
Agent agent(m_agentReference.getAgentAddress(), m_backend);
cta::objectstore::ScopedExclusiveLock agl(agent);
agent.fetch();
agent.removeAndUnregisterSelf();
}
//------------------------------------------------------------------------------
// getAgent
//------------------------------------------------------------------------------
cta::objectstore::Agent & BackendPopulator::getAgent() {
return m_agent;
cta::objectstore::AgentReference & BackendPopulator::getAgentReference() {
return m_agentReference;
}
}}
\ No newline at end of file
......@@ -19,6 +19,7 @@
#pragma once
#include "objectstore/Agent.hpp"
#include "objectstore/AgentReference.hpp"
#include "objectstore/Backend.hpp"
namespace cta { namespace objectstore {
......@@ -43,7 +44,7 @@ public:
*
* @return the agent
*/
cta::objectstore::Agent & getAgent();
cta::objectstore::AgentReference & getAgentReference();
private:
/**
......@@ -54,7 +55,7 @@ private:
/**
* The agent
*/
cta::objectstore::Agent m_agent;
cta::objectstore::AgentReference m_agentReference;
};
}}
\ No newline at end of file
......@@ -51,6 +51,7 @@ add_library (ctaobjectstore SHARED
${CTAProtoSources}
RootEntry.cpp
Agent.cpp
AgentReference.cpp
AgentRegister.cpp
AgentWatchdog.cpp
ArchiveQueue.cpp
......
......@@ -23,6 +23,7 @@
#include "GarbageCollector.hpp"
#include "RootEntry.hpp"
#include "Agent.hpp"
#include "AgentReference.hpp"
#include "AgentRegister.hpp"
#include "DriveRegister.hpp"
#include "ArchiveRequest.hpp"
......@@ -35,8 +36,8 @@ TEST(ObjectStore, GarbageCollectorBasicFuctionnality) {
// Here we check for the ability to detect dead (but empty agents)
// and clean them up.
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
cta::objectstore::AgentReference agentRef("unitTestGarbageCollector");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
......@@ -45,24 +46,23 @@ TEST(ObjectStore, GarbageCollectorBasicFuctionnality) {
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
rel.release();
// Create 2 agents, A and B and register them
// The agents are set with a timeout of 0, so they will be delclared
// dead immediately.
cta::objectstore::Agent agA(be), agB(be);
cta::objectstore::AgentReference agrA("unitTestAgentA"), agrB("unitTestAgentB");
cta::objectstore::Agent agA(agrA.getAgentAddress(), be), agB(agrB.getAgentAddress(), be);
agA.initialize();
agA.generateName("unitTestAgentA");
agA.setTimeout_us(0);
agA.insertAndRegisterSelf();
agB.initialize();
agB.generateName("unitTestAgentB");
agB.setTimeout_us(0);
agB.insertAndRegisterSelf();
// Create the garbage colletor and run it twice.
cta::objectstore::Agent gcAgent(be);
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector");
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
......@@ -83,8 +83,8 @@ TEST(ObjectStore, GarbageCollectorBasicFuctionnality) {
TEST(ObjectStore, GarbageCollectorRegister) {
// Here we check that can successfully call agentRegister's garbage collector
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
cta::objectstore::AgentReference agentRef("unitTestGarbageCollector");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
......@@ -93,19 +93,19 @@ TEST(ObjectStore, GarbageCollectorRegister) {
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
rel.release();
// Create an agent and add and agent register to it as an owned object
cta::objectstore::Agent agA(be);
cta::objectstore::AgentReference agrA("unitTestAgentA");
cta::objectstore::Agent agA(agrA.getAgentAddress(), 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 arName;
{
arName = agA.nextId("AgentRegister");
arName = agrA.nextId("AgentRegister");
cta::objectstore::AgentRegister ar(arName, be);
ar.initialize();
ar.setOwner(agA.getAddressIfSet());
......@@ -116,9 +116,9 @@ TEST(ObjectStore, GarbageCollectorRegister) {
ar.insert();
}
// Create the garbage colletor and run it twice.
cta::objectstore::Agent gcAgent(be);
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector");
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
......@@ -140,8 +140,8 @@ TEST(ObjectStore, GarbageCollectorRegister) {
TEST(ObjectStore, GarbageCollectorArchiveQueue) {
// Here we check that can successfully call agentRegister's garbage collector
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
cta::objectstore::AgentReference agentRef("unitTestGarbageCollector");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
......@@ -150,19 +150,19 @@ TEST(ObjectStore, GarbageCollectorArchiveQueue) {
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
rel.release();
// Create an agent and add and agent register to it as an owned object
cta::objectstore::Agent agA(be);
cta::objectstore::AgentReference agrA("unitTestAgentA");
cta::objectstore::Agent agA(agrA.getAgentAddress(), 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("ArchiveQueue");
tpName = agrA.nextId("ArchiveQueue");
cta::objectstore::ArchiveQueue aq(tpName, be);
aq.initialize("SomeTP");
aq.setOwner(agA.getAddressIfSet());
......@@ -173,9 +173,9 @@ TEST(ObjectStore, GarbageCollectorArchiveQueue) {
aq.insert();
}
// Create the garbage colletor and run it twice.
cta::objectstore::Agent gcAgent(be);
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector");
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
......@@ -197,8 +197,8 @@ TEST(ObjectStore, GarbageCollectorArchiveQueue) {
TEST(ObjectStore, GarbageCollectorDriveRegister) {
// Here we check that can successfully call agentRegister's garbage collector
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
cta::objectstore::AgentReference agentRef("unitTestGarbageCollector");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
......@@ -207,19 +207,19 @@ TEST(ObjectStore, GarbageCollectorDriveRegister) {
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
rel.release();
// Create an agent and add the drive register to it as an owned object
cta::objectstore::Agent agA(be);
cta::objectstore::AgentReference agrA("unitTestAgentA");
cta::objectstore::Agent agA(agrA.getAgentAddress(), be);
agA.initialize();
agA.generateName("unitTestAgentA");
agA.setTimeout_us(0);
agA.insertAndRegisterSelf();
// Create a new drive register, owned by agA (by hand as it is not an usual
// situation)
std::string tpName;
{
tpName = agA.nextId("ArchiveQueue");
tpName = agrA.nextId("ArchiveQueue");
cta::objectstore::DriveRegister dr(tpName, be);
dr.initialize();
dr.setOwner(agA.getAddressIfSet());
......@@ -230,9 +230,9 @@ TEST(ObjectStore, GarbageCollectorDriveRegister) {
dr.insert();
}
// Create the garbage colletor and run it twice.
cta::objectstore::Agent gcAgent(be);
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector");
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
......@@ -254,8 +254,8 @@ TEST(ObjectStore, GarbageCollectorDriveRegister) {
TEST(ObjectStore, GarbageCollectorArchiveRequest) {
// Here we check that can successfully call ArchiveRequests's garbage collector
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTestGarbageCollector");
cta::objectstore::AgentReference agentRef("unitTestGarbageCollector");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
// Create the root entry
cta::objectstore::RootEntry re(be);
re.initialize();
......@@ -264,12 +264,12 @@ TEST(ObjectStore, GarbageCollectorArchiveRequest) {
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::ScopedExclusiveLock rel(re);
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
rel.release();
// Create an agent
cta::objectstore::Agent agA(be);
cta::objectstore::AgentReference agrA("unitTestAgentA");
cta::objectstore::Agent agA(agrA.getAgentAddress(), be);
agA.initialize();
agA.generateName("unitTestAgentA");
agA.setTimeout_us(0);
agA.insertAndRegisterSelf();
// Several use cases are present for the ArchiveRequests:
......@@ -286,7 +286,7 @@ TEST(ObjectStore, GarbageCollectorArchiveRequest) {
{
std::stringstream aqid;
aqid << "ArchiveQueue" << i;
tpAddr[i] = agent.nextId(aqid.str());
tpAddr[i] = agentRef.nextId(aqid.str());
cta::objectstore::ArchiveQueue aq(tpAddr[i], be);
aq.initialize(aqid.str());
aq.setOwner("");
......@@ -297,7 +297,7 @@ TEST(ObjectStore, GarbageCollectorArchiveRequest) {
while (true)
{
// -just referenced
std::string atfrAddr = agA.nextId("ArchiveRequest");
std::string atfrAddr = agrA.nextId("ArchiveRequest");
cta::objectstore::ScopedExclusiveLock agl(agA);
agA.fetch();
agA.addToOwnership(atfrAddr);
......@@ -383,9 +383,9 @@ TEST(ObjectStore, GarbageCollectorArchiveRequest) {
break;
}
// Create the garbage collector and run it twice.
cta::objectstore::Agent gcAgent(be);
cta::objectstore::AgentReference gcAgentRef("unitTestGarbageCollector");
cta::objectstore::Agent gcAgent(gcAgentRef.getAgentAddress(), be);
gcAgent.initialize();
gcAgent.generateName("unitTestGarbageCollector");
gcAgent.setTimeout_us(0);
gcAgent.insertAndRegisterSelf();
{
......
......@@ -19,15 +19,14 @@
#include <gtest/gtest.h>
#include "RetrieveQueue.hpp"
#include "BackendVFS.hpp"
#include "Agent.hpp"
#include "AgentReference.hpp"
namespace unitTests {
TEST(ObjectStore, RetrieveQueueBasicAccess) {
cta::objectstore::BackendVFS be;
cta::objectstore::Agent agent(be);
agent.generateName("unitTest");
std::string retrieveQueueAddress = agent.nextId("RetrieveQueue");
cta::objectstore::AgentReference agentRef("unitTest");
std::string retrieveQueueAddress = agentRef.nextId("RetrieveQueue");
{
// Try to create the tape entry
cta::objectstore::RetrieveQueue rq(retrieveQueueAddress, be);
......
......@@ -19,6 +19,7 @@
#include "RootEntry.hpp"
#include "AgentRegister.hpp"
#include "Agent.hpp"
#include "AgentReference.hpp"
#include "ArchiveQueue.hpp"
#include "RetrieveQueue.hpp"
#include "DriveRegister.hpp"
......@@ -93,7 +94,7 @@ namespace {
}
}
std::string RootEntry::addOrGetArchiveQueueAndCommit(const std::string& tapePool, Agent& agent) {
std::string RootEntry::addOrGetArchiveQueueAndCommit(const std::string& tapePool, AgentReference& agentRef) {
checkPayloadWritable();
// Check the archive queue does not already exist
try {
......@@ -101,8 +102,9 @@ std::string RootEntry::addOrGetArchiveQueueAndCommit(const std::string& tapePool
} catch (serializers::NotFound &) {}
// Insert the archive queue, then its pointer, with agent intent log update
// First generate the intent. We expect the agent to be passed locked.
std::string archiveQueueAddress = agent.nextId("archiveQueue");
std::string archiveQueueAddress = agentRef.nextId("archiveQueue");
// TODO Do we expect the agent to be passed locked or not: to be clarified.
Agent agent(agentRef.getAgentAddress(), m_objectStore);
ScopedExclusiveLock agl(agent);
agent.fetch();
agent.addToOwnership(archiveQueueAddress);
......@@ -213,7 +215,7 @@ namespace {
}
}
std::string RootEntry::addOrGetRetrieveQueueAndCommit(const std::string& vid, Agent& agent) {
std::string RootEntry::addOrGetRetrieveQueueAndCommit(const std::string& vid, AgentReference& agentRef) {
checkPayloadWritable();
// Check the retrieve queue does not already exist
try {
......@@ -221,8 +223,9 @@ std::string RootEntry::addOrGetRetrieveQueueAndCommit(const std::string& vid, Ag
} catch (serializers::NotFound &) {}
// Insert the retrieve queue, then its pointer, with agent intent log update
// First generate the intent. We expect the agent to be passed locked.
std::string retrieveQueueAddress = agent.nextId("retriveQueue");
std::string retrieveQueueAddress = agentRef.nextId("retriveQueue");
// TODO Do we expect the agent to be passed locked or not: to be clarified.
Agent agent(agentRef.getAgentAddress(), m_objectStore);
ScopedExclusiveLock agl(agent);
agent.fetch();
agent.addToOwnership(retrieveQueueAddress);
......@@ -324,7 +327,7 @@ auto RootEntry::dumpRetrieveQueues() -> std::list<RetrieveQueueDump> {
// =============================================================================
std::string RootEntry::addOrGetDriveRegisterPointerAndCommit(
Agent & agent, const EntryLogSerDeser & log) {
AgentReference& agentRef, const EntryLogSerDeser & log) {
checkPayloadWritable();
// Check if the drive register exists
try {
......@@ -332,7 +335,8 @@ std::string RootEntry::addOrGetDriveRegisterPointerAndCommit(
} catch (NotAllocated &) {
// decide on the object's name and add to agent's intent. We expect the
// agent to be passed locked.
std::string drAddress (agent.nextId("driveRegister"));
std::string drAddress (agentRef.nextId("driveRegister"));
Agent agent(agentRef.getAgentAddress(), m_objectStore);
ScopedExclusiveLock agl(agent);
agent.fetch();
agent.addToOwnership(drAddress);
......@@ -408,7 +412,7 @@ std::string RootEntry::getAgentRegisterAddress() {
}
// Get the name of a (possibly freshly created) agent register
std::string RootEntry::addOrGetAgentRegisterPointerAndCommit(Agent & agent,
std::string RootEntry::addOrGetAgentRegisterPointerAndCommit(AgentReference& agentRef,
const EntryLogSerDeser & log) {
// Check if the agent register exists
try {
......@@ -424,7 +428,7 @@ std::string RootEntry::addOrGetAgentRegisterPointerAndCommit(Agent & agent,
return m_payload.agentregisterpointer().address();
}
// decide on the object's name
std::string arAddress (agent.nextId("agentRegister"));
std::string arAddress (agentRef.nextId("agentRegister"));
// Record the agent registry in our own intent
addIntendedAgentRegistry(arAddress);
commit();
......@@ -535,7 +539,7 @@ std::string RootEntry::getSchedulerGlobalLock() {
}
// Get the name of a (possibly freshly created) scheduler global lock
std::string RootEntry::addOrGetSchedulerGlobalLockAndCommit(Agent & agent,
std::string RootEntry::addOrGetSchedulerGlobalLockAndCommit(AgentReference& agentRef,
const EntryLogSerDeser & log) {
checkPayloadWritable();
// Check if the drive register exists
......@@ -544,7 +548,8 @@ std::string RootEntry::addOrGetSchedulerGlobalLockAndCommit(Agent & agent,
} catch (NotAllocated &) {
// decide on the object's name and add to agent's intent. We expect the
// agent to be passed locked.
std::string sglAddress (agent.nextId("schedulerGlobalLock"));
std::string sglAddress (agentRef.nextId("schedulerGlobalLock"));
Agent agent(agentRef.getAgentAddress(), m_objectStore);
ScopedExclusiveLock agl(agent);
agent.fetch();
agent.addToOwnership(sglAddress);
......
......@@ -29,7 +29,7 @@
namespace cta { namespace objectstore {
class Agent;
class AgentReference;
class GenericObject;
class RootEntry: public ObjectOps<serializers::RootEntry, serializers::RootEntry_t> {
......@@ -55,7 +55,7 @@ public:
CTA_GENERATE_EXCEPTION_CLASS(WrongArchiveQueue);
/** This function implicitly creates the archive queue structure and updates
* the pointer to it. It will implicitly commit the object to the store. */
std::string addOrGetArchiveQueueAndCommit(const std::string & tapePool, Agent & agent);
std::string addOrGetArchiveQueueAndCommit(const std::string & tapePool, AgentReference & agentRef);
/** This function implicitly deletes the tape pool structure.
* Fails if it not empty*/
CTA_GENERATE_EXCEPTION_CLASS(NoSuchArchiveQueue);
......@@ -72,7 +72,7 @@ public:
CTA_GENERATE_EXCEPTION_CLASS(RetrieveQueueNotEmpty);
/** This function implicitly creates the retrieve queue structure and updates
* the pointer to it. It will implicitly commit the object to the store. */
std::string addOrGetRetrieveQueueAndCommit(const std::string & vid, Agent & agent);
std::string addOrGetRetrieveQueueAndCommit(const std::string & vid, AgentReference & agentRef);
CTA_GENERATE_EXCEPTION_CLASS(NoSuchRetrieveQueue);
void removeRetrieveQueueAndCommit(const std::string & vid);
std::string getRetrieveQueue(const std::string & vid);
......@@ -85,7 +85,7 @@ public:
// Drive register manipulations ==============================================
CTA_GENERATE_EXCEPTION_CLASS(DriveRegisterNotEmpty);
std::string getDriveRegisterAddress();
std::string addOrGetDriveRegisterPointerAndCommit(Agent & agent, const EntryLogSerDeser & log);
std::string addOrGetDriveRegisterPointerAndCommit(AgentReference & agentRef, const EntryLogSerDeser & log);
void removeDriveRegisterAndCommit();
// Agent register manipulations ==============================================
......@@ -95,13 +95,13 @@ public:
* is used to generate the object name. We have the dedicated agent intent
* log for tracking objects being created. We already use an agent here for
* object name generation, but not yet tracking. */
std::string addOrGetAgentRegisterPointerAndCommit(Agent & agent,
std::string addOrGetAgentRegisterPointerAndCommit(AgentReference & agentRef,
const EntryLogSerDeser & log);
void removeAgentRegisterAndCommit();
// Agent register manipulations ==============================================
std::string getSchedulerGlobalLock();
std::string addOrGetSchedulerGlobalLockAndCommit(Agent & agent, const EntryLogSerDeser & log);
std::string addOrGetSchedulerGlobalLockAndCommit(AgentReference & agentRef, const EntryLogSerDeser & log);
void removeSchedulerGlobalLockAndCommit();
private:
......
......@@ -22,6 +22,7 @@
#include "objectstore/SerializersExceptions.hpp"
#include "RootEntry.hpp"
#include "Agent.hpp"
#include "AgentReference.hpp"
#include "AgentRegister.hpp"
#include "ArchiveQueue.hpp"
......@@ -49,12 +50,12 @@ TEST(ObjectStore, RootEntryBasicAccess) {
cta::objectstore::RootEntry re(be);
cta::objectstore::ScopedExclusiveLock lock (re);
// Create an agent
cta::objectstore::Agent agent(be);
agent.generateName("unitTest");
cta::objectstore::AgentReference agentRef("unitTest");
cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
re.fetch();
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
re.addOrGetAgentRegisterPointerAndCommit(agent, el);
re.addOrGetAgentRegisterPointerAndCommit(agentRef, el);
ASSERT_NO_THROW(re.getAgentRegisterAddress());
re.commit();
//agent.registerSelf();
......@@ -72,16 +73,16 @@ TEST (ObjectStore, RootEntryArchiveQueues) {
cta::objectstore::BackendVFS be;
cta::objectstore::EntryLogSerDeser el("user0",
"unittesthost", time(NULL));
cta::objectstore::Agent ag(be);
cta::objectstore::AgentReference agr("UnitTests");
cta::objectstore::Agent ag(agr.getAgentAddress(), be);
ag.initialize();
ag.generateName("UnitTests");
{
// Try to create the root entry and allocate the agent register
cta::objectstore::RootEntry re(be);