Commit 348c073d authored by Steven Murray's avatar Steven Murray
Browse files

Cleaned up CleanerSession creation logic for labeling tapes

parent 3bd5e6a0
......@@ -524,12 +524,12 @@ void castor::tape::tapeserver::daemon::CatalogueDrive::receivedLabelJob(
//-----------------------------------------------------------------------------
// createCleaner
//-----------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::CatalogueDrive::createCleaner(
castor::tape::tapeserver::daemon::CatalogueCleanerSession
*castor::tape::tapeserver::daemon::CatalogueDrive::createCleaner(
const std::string &vid, const time_t assignmentTime,
const uint32_t driveReadyDelayInSeconds) {
const uint32_t driveReadyDelayInSeconds) const {
try {
// Create a cleaner session
m_session = CatalogueCleanerSession::create(
return CatalogueCleanerSession::create(
m_log,
m_netTimeout,
m_config,
......@@ -617,7 +617,7 @@ void castor::tape::tapeserver::daemon::CatalogueDrive::runningSessionFailed() {
if(CatalogueSession::SESSION_TYPE_CLEANER != session->getType()) {
const uint32_t driveReadyDelayInSeconds = 60;
createCleaner(session->getVid(), session->getAssignmentTime(),
m_session = createCleaner(session->getVid(), session->getAssignmentTime(),
driveReadyDelayInSeconds);
} else {
changeState(DRIVE_STATE_DOWN);
......@@ -636,7 +636,7 @@ void castor::tape::tapeserver::daemon::CatalogueDrive::
changeState(DRIVE_STATE_WAITSHUTDOWNCLEANER);
const uint32_t driveReadyDelayInSeconds = 60;
createCleaner(session->getVid(), session->getAssignmentTime(),
m_session = createCleaner(session->getVid(), session->getAssignmentTime(),
driveReadyDelayInSeconds);
}
......@@ -653,6 +653,62 @@ void castor::tape::tapeserver::daemon::CatalogueDrive::
changeState(DRIVE_STATE_SHUTDOWN);
}
//------------------------------------------------------------------------------
// sessionFailedAndRequestsCleaner
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::CatalogueDrive::
sessionFailedAndRequestsCleaner() {
switch(m_state) {
case DRIVE_STATE_RUNNING:
case DRIVE_STATE_WAITDOWN:
return runningSessionFailedAndRequestedCleaner();
default:
{
castor::exception::Exception ex;
ex.getMessage() <<
"Failed to record tape session failed for session with pid " <<
getSession().getPid() << ": Incompatible drive state: state=" <<
driveStateToStr(m_state);
delete m_session;
m_session = NULL;
throw ex;
}
}
}
//------------------------------------------------------------------------------
// runningSessionFailedAndRequestedCleaner
//------------------------------------------------------------------------------
void castor::tape::tapeserver::daemon::CatalogueDrive::
runningSessionFailedAndRequestedCleaner() {
{
const pid_t sessionPid = m_session->getPid();
const CatalogueSession::Type sessionType = m_session->getType();
const char *sessionTypeStr =
CatalogueSession::sessionTypeToStr(sessionType);
std::list<log::Param> params;
params.push_back(log::Param("unitName", m_config.unitName));
params.push_back(log::Param("sessionType", sessionTypeStr));
params.push_back(log::Param("sessionPid", sessionPid));
m_log(LOG_INFO, "Failed session has requested cleaner", params);
}
std::auto_ptr<CatalogueSession> session(m_session);
m_session = NULL;
session->sessionFailed();
if(CatalogueSession::SESSION_TYPE_CLEANER != session->getType()) {
const uint32_t driveReadyDelayInSeconds = 60;
m_session = createCleaner(session->getVid(), session->getAssignmentTime(),
driveReadyDelayInSeconds);
} else {
changeState(DRIVE_STATE_DOWN);
m_vdqm.setDriveDown(m_hostName, m_config.unitName, m_config.dgn);
}
}
//------------------------------------------------------------------------------
// getTapeStatDriveEntry
//------------------------------------------------------------------------------
......@@ -833,7 +889,7 @@ void castor::tape::tapeserver::daemon::CatalogueDrive::shutdown() {
const std::string vid = ""; // Empty string means VID is not known
const time_t assignmentTime = time(NULL);
const uint32_t driveReadyDelayInSeconds = 0;
createCleaner(vid, assignmentTime, driveReadyDelayInSeconds);
m_session = createCleaner(vid, assignmentTime, driveReadyDelayInSeconds);
// Else there is a running session
} else {
......
......@@ -326,37 +326,21 @@ public:
const int labelCmdConnection);
/**
* Creates a cleaner session to eject any tape left in the tape drive.
*
* @param vid The volume identifier of the tape currently in the tape drive
* or the empty string if not know.
* @param The assignment time associated with the tape drive or 0 if not
* known. The assignment time is given as the number of seconds elapsed
* since the Epoch.
* @param driveReadyDelayInSeconds The maximum number of seconds to wait for
* the drive to be raedy with a tape inside of it.
*/
void createCleaner(const std::string &vid, const time_t assignmentTime,
const uint32_t driveReadyDelayInSeconds);
/**
* Moves the state of the tape drive to DRIVE_STATE_UP if the
* current state is DRIVE_STATE_RUNNING or to DRIVE_STATE_DOWN if the
* current state is DRIVE_STATE_WAIT_DOWN.
*
* This method throws an exception if the current state of the tape drive is
* not DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN.
* Informs catalogue drive that the current tape session has succeeded.
*/
void sessionSucceeded();
/**
* Moves the state of tape drive to DRIVE_STATE_DOWN.
*
* This method throws an exception if the current state of the tape drive is
* not DRIVE_STATE_RUNNING.
* Informs catalogue drive that the current tape session has failed.
*/
void sessionFailed();
/**
* Informs catalogue drive that the current tape session has failed and that
* it has requested a CleanerSession.
*/
void sessionFailedAndRequestsCleaner();
/**
* Gets the tpstat representation of the tape drive.
*
......@@ -667,6 +651,27 @@ private:
*/
void cleanerOfShutdownFailed();
/**
* Called when a running session (DRIVE_STATE_RUNNING or DRIVE_STATE_WAITDOWN)
* has failed and has requested a CleanerSession.
*/
void runningSessionFailedAndRequestedCleaner();
/**
* Creates a cleaner session to eject any tape left in the tape drive.
*
* @param vid The volume identifier of the tape currently in the tape drive
* or the empty string if not know.
* @param The assignment time associated with the tape drive or 0 if not
* known. The assignment time is given as the number of seconds elapsed
* since the Epoch.
* @param driveReadyDelayInSeconds The maximum number of seconds to wait for
* the drive to be raedy with a tape inside of it.
* @return The catalogue cleaner-session.
*/
CatalogueCleanerSession *createCleaner(const std::string &vid,
const time_t assignmentTime, const uint32_t driveReadyDelayInSeconds) const;
}; // class CatalogueDrive
} // namespace daemon
......
......@@ -115,7 +115,7 @@ castor::tape::tapeserver::daemon::CatalogueLabelSession::
}
//------------------------------------------------------------------------------
// handlTick
// handleTick
//------------------------------------------------------------------------------
bool castor::tape::tapeserver::daemon::CatalogueLabelSession::handleTick() {
return true; // Continue the main event loop
......
......@@ -237,14 +237,7 @@ void castor::tape::tapeserver::daemon::ProcessForkerConnectionHandler::
case Session::MARK_DRIVE_AS_DOWN:
return drive.sessionFailed();
case Session::CLEAN_DRIVE:
{
const std::string vid = drive.getVidForCleaner();
const time_t assignmentTime = drive.getAssignmentTimeForCleaner();
drive.sessionFailed();
const uint32_t driveReadyDelayInSeconds = 60;
return drive.createCleaner(vid, assignmentTime,
driveReadyDelayInSeconds);
}
return drive.sessionFailedAndRequestsCleaner();
default:
// Should never happen
{
......
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