Commit 03c8f18a authored by Cedric Caffy's avatar Cedric Caffy
Browse files

cta-taped checks the drive does not already exist before starting.

A drive name is unique within all CTA. At startup, if the name already
exists, we check that the library and the host corresponds to what we
have from the configuration. If not, the drive will not start.
parent 2b558404
File mode changed from 100644 to 100755
......@@ -2910,6 +2910,31 @@ void OStoreDB::reportDriveConfig(const cta::tape::daemon::TpconfigLine& tpConfig
ds.setConfig(tapedConfig);
ds.setTpConfig(tpConfigLine);
ds.commit();
}
void OStoreDB::checkDriveCanBeCreated(const cta::common::dataStructures::DriveInfo & driveInfo) {
objectstore::RootEntry re(m_objectStore);
re.fetchNoLock();
objectstore::DriveRegister dr(re.getDriveRegisterAddress(),m_objectStore);
ScopedExclusiveLock sel(dr);
dr.fetch();
try {
std::string driveAddress = dr.getDriveAddress(driveInfo.driveName);
objectstore::DriveState ds(driveAddress,m_objectStore);
ds.fetchNoLock();
cta::common::dataStructures::DriveState driveState = ds.getState();
if(driveState.logicalLibrary != driveInfo.logicalLibrary || driveState.host != driveInfo.host) {
throw cta::SchedulerDatabase::DriveAlreadyExistsException(std::string("The drive name=") + driveInfo.driveName +
" logicalLibrary=" + driveInfo.logicalLibrary +
" host=" + driveInfo.host +
" cannot be created because a drive with a same name with logicalLibrary=" + driveState.logicalLibrary +
" host=" + driveState.host +
" already exists.");
}
} catch (cta::objectstore::DriveRegister::NoSuchDrive & ex) {
//Drive does not exist
//We can create it, do nothing then
}
}
//------------------------------------------------------------------------------
......
......@@ -555,6 +555,8 @@ public:
void reportDriveConfig(const cta::tape::daemon::TpconfigLine& tpConfigLine, const cta::tape::daemon::TapedConfiguration& tapedConfig,log::LogContext& lc) override;
void checkDriveCanBeCreated(const cta::common::dataStructures::DriveInfo & driveInfo) override;
/* --- Private helper part implementing state transition logic -------------*/
/*
* The drive register should gracefully handle reports of status from the drive
......
......@@ -279,6 +279,11 @@ public:
void reportDriveConfig(const cta::tape::daemon::TpconfigLine& tpConfigLine, const cta::tape::daemon::TapedConfiguration& tapedConfig,log::LogContext& lc) override {
m_OStoreDB.reportDriveConfig(tpConfigLine, tapedConfig,lc);
}
void checkDriveCanBeCreated(const cta::common::dataStructures::DriveInfo & driveInfo) override {
m_OStoreDB.checkDriveCanBeCreated(driveInfo);
}
private:
std::unique_ptr <cta::log::Logger> m_logger;
......
......@@ -91,7 +91,7 @@ namespace cta {
*/
class SchedulerDatabase {
public:
CTA_GENERATE_EXCEPTION_CLASS(DriveAlreadyExistsException);
/**
* Destructor.
*/
......@@ -781,6 +781,9 @@ public:
const std::string & tapepool = "") = 0;
virtual void reportDriveConfig(const cta::tape::daemon::TpconfigLine& tpConfigLine, const cta::tape::daemon::TapedConfiguration& tapedConfig,log::LogContext& lc) = 0;
virtual void checkDriveCanBeCreated(const cta::common::dataStructures::DriveInfo & driveInfo) = 0;
}; // class SchedulerDatabase
} // namespace cta
......@@ -42,6 +42,8 @@
namespace cta { namespace tape { namespace daemon {
CTA_GENERATE_EXCEPTION_CLASS(DriveAlreadyExistException);
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
......@@ -1086,6 +1088,21 @@ int DriveHandler::runChild() {
driveInfo.driveName=m_configLine.unitName;
driveInfo.logicalLibrary=m_configLine.logicalLibrary;
driveInfo.host=hostname;
//Checking the drive does not already exist in the objectstore
try{
osdb->checkDriveCanBeCreated(driveInfo);
} catch (SchedulerDatabase::DriveAlreadyExistsException &ex) {
log::ScopedParamContainer param(lc);
param.add("tapeDrive",driveInfo.driveName)
.add("logicalLibrary",driveInfo.logicalLibrary)
.add("host",driveInfo.host)
.add("exceptionMsg",ex.getMessageValue());
lc.log(log::CRIT,"In DriveHandler::runChild(): drive already exists. Reporting fatal error.");
driveHandlerProxy.reportState(tape::session::SessionState::Fatal, tape::session::SessionType::Undetermined, "");
return castor::tape::tapeserver::daemon::Session::MARK_DRIVE_AS_DOWN;
}
scheduler.reportDriveStatus(driveInfo, common::dataStructures::MountType::NoMount, common::dataStructures::DriveStatus::Down, lc);
cta::common::dataStructures::SecurityIdentity securityIdentity;
scheduler.setDesiredDriveState(securityIdentity, m_configLine.unitName, false /* down */, false /* no force down*/, lc);
......
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