Commit c5e3fba0 authored by Eric Cano's avatar Eric Cano
Browse files

Added a next state structure for the drive register.

Added during investigation of scheduling issues.
Not used currently but will be usefull when implementing session preemption.
parent 2e2aabf5
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
#include "MountType.hpp"
namespace cta {
namespace common {
namespace dataStructures {
/**
* This struct holds minimal drive info. It is used to (re-)create the
* drive's entry in the register is needed.
*/
struct DriveNextState {
std::string driveName;
MountType mountType;
std::string vid;
std::string tapepool;
};
}}} //namespace cta::common::dataStructures
\ No newline at end of file
......@@ -44,7 +44,8 @@ DriveState::DriveState():
startStartTime(0),
mountType(dataStructures::MountType::NoMount),
driveStatus(dataStructures::DriveStatus::Down),
desiredDriveState({false, false}) {}
desiredDriveState({false, false}),
nextMountType(dataStructures::MountType::NoMount) {}
//------------------------------------------------------------------------------
// operator==
......@@ -71,7 +72,10 @@ bool DriveState::operator==(const DriveState &rhs) const {
&& driveStatus==rhs.driveStatus
&& desiredDriveState==rhs.desiredDriveState
&& currentVid==rhs.currentVid
&& currentTapePool==rhs.currentTapePool;
&& currentTapePool==rhs.currentTapePool
&& nextMountType == rhs.nextMountType
&& nextTapepool == rhs.nextTapepool
&& nextVid == rhs.nextVid;
}
//------------------------------------------------------------------------------
......@@ -107,7 +111,10 @@ std::ostream &operator<<(std::ostream &os, const DriveState &obj) {
<< " status=" << obj.driveStatus
<< " desiredState=" << obj.desiredDriveState
<< " currentVid=" << obj.currentVid
<< " currentTapePool=" << obj.currentTapePool << ")";
<< " currentTapePool=" << obj.currentTapePool
<< " nextMountType=" << obj.nextMountType
<< " nextVid=" << obj.nextVid
<< " nextTapePool=" << obj.nextTapepool << ")";
}
} // namespace dataStructures
......
......@@ -63,6 +63,9 @@ struct DriveState {
DesiredDriveState desiredDriveState;
std::string currentVid;
std::string currentTapePool;
MountType nextMountType;
std::string nextVid;
std::string nextTapepool;
}; // struct DriveState
......
......@@ -132,6 +132,9 @@ std::list<cta::common::dataStructures::DriveState> DriveRegister::getAllDrivesSt
ret.back().desiredDriveState.forceDown = d.desiredforcedown();
ret.back().currentVid = d.currentvid();
ret.back().currentTapePool = d.currenttapepool();
if (d.has_nextmounttype()) { ret.back().nextMountType = (common::dataStructures::MountType) d.nextmounttype(); }
if (d.has_nexttapepool()) { ret.back().nextTapepool = d.nexttapepool(); }
if (d.has_nextvid()) { ret.back().nextVid = d.nextvid(); }
}
return ret;
}
......@@ -218,6 +221,43 @@ update:
}
//------------------------------------------------------------------------------
// DriveRegister::setNextDriveState())
//------------------------------------------------------------------------------
void DriveRegister::setNextDriveState(const cta::common::dataStructures::DriveNextState driveNextState) {
using cta::common::dataStructures::MountType;
checkPayloadWritable();
// Find the drive to update (new or existing)
serializers::DriveState * ds = nullptr;
for (ssize_t i=0; i<m_payload.mutable_drives()->size(); i++) {
if (m_payload.mutable_drives(i)->drivename() == driveNextState.driveName) {
ds = m_payload.mutable_drives(i);
goto update;
}
}
// The drive was not found. We will create it.
ds = m_payload.mutable_drives()->Add();
ds->set_drivename(driveNextState.driveName);
update:
switch(driveNextState.mountType) {
case MountType::Archive:
ds->set_nexttapepool(driveNextState.tapepool);
// No break on purpose.
case MountType::Label:
case MountType::Retrieve:
ds->set_nextmounttype((int)driveNextState.mountType);
ds->set_nextvid(driveNextState.vid);
break;
default:
{
std::stringstream err;
err << "In DriveRegister::setNextDriveState(): unknown mount type: "
<< cta::common::dataStructures::toString(driveNextState.mountType);
throw cta::exception::Exception(err.str());
}
}
}
//------------------------------------------------------------------------------
// DriveRegister::isEmpty())
//------------------------------------------------------------------------------
......
......@@ -22,6 +22,7 @@
#include <list>
#include <limits>
#include "common/dataStructures/DriveState.hpp"
#include "common/dataStructures/DriveNextState.hpp"
namespace cta { namespace objectstore {
......@@ -60,6 +61,13 @@ public:
* @param driveState Full drive state (drive name is part of the structure).
*/
void setDriveState(const cta::common::dataStructures::DriveState driveState);
/**
* Set the next state of a drive, following a mount decision (scheduling from
* idle or preemption).
* @param driveNextState Partial drive state.
*/
void setNextDriveState(const cta::common::dataStructures::DriveNextState driveNextState);
/**
* Remove the drive from the register.
......
......@@ -283,6 +283,9 @@ message DriveState {
required bool desiredForceDown = 5020;
optional string currentvid = 5021;
optional string currenttapepool = 5022;
optional uint32 nextmounttype = 5023;
optional string nextvid = 5024;
optional string nexttapepool = 5025;
// TODO: implement or remove required EntryLog creationlog = 5023;
}
......
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