Commit c6dd6e2b authored by Cedric Caffy's avatar Cedric Caffy
Browse files

[lto_rao] Determined band and landing zone on the InterpolationFilePositionEstimator

parent c372350e
......@@ -18,7 +18,7 @@ set(CTARAO_LIBRARY_SRCS
SLTFRAOAlgorithm.cpp
RAOOptions.cpp
CostHeuristic.cpp
FilePosition.cpp
FilePositionInfos.cpp
Position.cpp
FilePositionEstimator.cpp
InterpolationFilePositionEstimator.cpp
......
......@@ -18,7 +18,7 @@
#pragma once
#include "FilePosition.hpp"
#include "FilePositionInfos.hpp"
#include "scheduler/RetrieveJob.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
......@@ -26,7 +26,7 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
class FilePositionEstimator {
public:
FilePositionEstimator();
virtual FilePosition getFilePosition(const cta::RetrieveJob & job) const = 0;
virtual FilePositionInfos getFilePosition(const cta::RetrieveJob & job) const = 0;
virtual ~FilePositionEstimator();
private:
......
......@@ -16,31 +16,87 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FilePosition.hpp"
#include "FilePositionInfos.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
FilePosition::FilePosition() {
FilePositionInfos::FilePositionInfos() {
}
FilePosition::~FilePosition() {
FilePositionInfos::FilePositionInfos(const FilePositionInfos& other){
if(this != &other){
m_startPosition = other.m_startPosition;
m_endPosition = other.m_endPosition;
m_startBand = other.m_startBand;
m_endBand = other.m_endBand;
m_startLandingZone = other.m_startLandingZone;
m_endLandingZone = other.m_endLandingZone;
}
}
void FilePosition::setStartPosition(const Position & startPosition) {
FilePositionInfos & FilePositionInfos::operator =(const FilePositionInfos& other){
if(this != &other){
m_startPosition = other.m_startPosition;
m_endPosition = other.m_endPosition;
m_startBand = other.m_startBand;
m_endBand = other.m_endBand;
m_startLandingZone = other.m_startLandingZone;
m_endLandingZone = other.m_endLandingZone;
}
return *this;
}
FilePositionInfos::~FilePositionInfos() {
}
void FilePositionInfos::setStartPosition(const Position & startPosition) {
m_startPosition = startPosition;
}
void FilePosition::setEndPosition(const Position& endPosition) {
void FilePositionInfos::setEndPosition(const Position& endPosition) {
m_endPosition = endPosition;
}
Position FilePosition::getStartPosition() const {
Position FilePositionInfos::getStartPosition() const {
return m_startPosition;
}
Position FilePosition::getEndPosition() const {
Position FilePositionInfos::getEndPosition() const {
return m_endPosition;
}
void FilePositionInfos::setStartBand(const uint8_t startBand){
m_startBand = startBand;
}
void FilePositionInfos::setEndBand(const uint8_t endBand){
m_endBand = endBand;
}
void FilePositionInfos::setStartLandingZone(const uint8_t startLandingZone){
m_startLandingZone = startLandingZone;
}
void FilePositionInfos::setEndLandingZone(const uint8_t endLandingZone){
m_endLandingZone = endLandingZone;
}
uint8_t FilePositionInfos::getStartBand() const {
return m_startBand;
}
uint8_t FilePositionInfos::getEndBand() const {
return m_endBand;
}
uint8_t FilePositionInfos::getStartLandingZone() const {
return m_startLandingZone;
}
uint8_t FilePositionInfos::getEndLandingZone() const {
return m_endLandingZone;
}
}}}}
\ No newline at end of file
......@@ -23,17 +23,31 @@
namespace castor { namespace tape { namespace tapeserver { namespace rao {
class FilePosition {
class FilePositionInfos {
public:
FilePosition();
FilePositionInfos();
FilePositionInfos(const FilePositionInfos & other);
FilePositionInfos & operator=(const FilePositionInfos & other);
void setStartPosition(const Position & startPosition);
void setEndPosition(const Position & endPosition);
void setStartBand(const uint8_t startBand);
void setEndBand(const uint8_t endBand);
void setStartLandingZone(const uint8_t startLandingZone);
void setEndLandingZone(const uint8_t endLandingZone);
Position getStartPosition() const;
Position getEndPosition() const;
virtual ~FilePosition();
uint8_t getStartBand() const;
uint8_t getEndBand() const;
uint8_t getStartLandingZone() const;
uint8_t getEndLandingZone() const;
virtual ~FilePositionInfos();
private:
Position m_startPosition;
Position m_endPosition;
uint8_t m_startBand;
uint8_t m_endBand;
uint8_t m_startLandingZone;
uint8_t m_endLandingZone;
};
}}}}
\ No newline at end of file
......@@ -17,18 +17,20 @@
*/
#include "InterpolationFilePositionEstimator.hpp"
#include "RAOHelpers.hpp"
namespace castor { namespace tape { namespace tapeserver { namespace rao {
InterpolationFilePositionEstimator::InterpolationFilePositionEstimator(const std::vector<drive::endOfWrapPosition> & endOfWrapPositions,
const cta::catalogue::MediaType & mediaType): m_endOfWrapPositions(endOfWrapPositions), m_mediaType(mediaType) {
checkMediaTypeConsistency();
}
InterpolationFilePositionEstimator::~InterpolationFilePositionEstimator() {
}
FilePosition InterpolationFilePositionEstimator::getFilePosition(const cta::RetrieveJob& job) const {
FilePosition ret;
FilePositionInfos InterpolationFilePositionEstimator::getFilePosition(const cta::RetrieveJob& job) const {
FilePositionInfos ret;
cta::common::dataStructures::TapeFile tapeFile = job.selectedTapeFile();
uint64_t startBlock = tapeFile.blockId;
Position startPosition = getPhysicalPosition(startBlock);
......@@ -36,6 +38,14 @@ FilePosition InterpolationFilePositionEstimator::getFilePosition(const cta::Retr
uint64_t endBlock = determineEndBlock(tapeFile);
Position endPosition = getPhysicalPosition(endBlock);
ret.setEndPosition(endPosition);
if(!m_mediaType.nbWraps){
std::string errorMsg = "In InterpolationFilePositionEstimator::getFilePosition(), the media type " + m_mediaType.name+" does not contain any information about the number of wraps the media has.";
throw cta::exception::Exception(errorMsg);
}
ret.setStartBand(RAOHelpers::determineBand(m_mediaType.nbWraps.value(),startPosition.getWrap()));
ret.setEndBand(RAOHelpers::determineBand(m_mediaType.nbWraps.value(),endPosition.getWrap()));
ret.setStartLandingZone(RAOHelpers::determineLandingZone(m_mediaType.minLPos.value(),m_mediaType.maxLPos.value(),startPosition.getLPos()));
ret.setEndLandingZone(RAOHelpers::determineLandingZone(m_mediaType.minLPos.value(),m_mediaType.maxLPos.value(),endPosition.getLPos()));
return ret;
}
......@@ -64,16 +74,10 @@ uint64_t InterpolationFilePositionEstimator::determineWrapNb(const uint64_t bloc
}
uint64_t InterpolationFilePositionEstimator::determineLPos(const uint64_t blockId, const uint64_t wrapNumber) const {
uint64_t fileLpos;
cta::optional<uint64_t> minTapeLpos = m_mediaType.minLPos;
cta::optional<uint64_t> maxTapeLpos = m_mediaType.maxLPos;
uint64_t retLpos;
uint64_t fileBlockId = blockId;
if(!minTapeLpos || !maxTapeLpos){
std::string errorMsg = "In InterpolationFilePositionEstimator::determineLPos(), the media type (" + m_mediaType.name + ") associated to the tape tape does not give informations about the minLPos and maxLPos.";
throw cta::exception::Exception(errorMsg);
}
uint64_t minLpos = minTapeLpos.value();
uint64_t maxLpos = maxTapeLpos.value();
uint64_t minLpos = m_mediaType.minLPos.value();
uint64_t maxLpos = m_mediaType.maxLPos.value();
uint64_t b_max = m_endOfWrapPositions.at(wrapNumber).blockId;
if(wrapNumber > 0){
drive::endOfWrapPosition previousWrapPositionInfos = m_endOfWrapPositions.at(wrapNumber-1);
......@@ -81,15 +85,27 @@ uint64_t InterpolationFilePositionEstimator::determineLPos(const uint64_t blockI
fileBlockId -= previousWrapPositionInfos.blockId;
}
if(wrapNumber % 2 == 0){
fileLpos = minLpos + fileBlockId * (maxLpos - minLpos) / (double)b_max;
retLpos = minLpos + fileBlockId * (maxLpos - minLpos) / (double)b_max;
} else {
fileLpos = maxLpos - fileBlockId * (maxLpos - minLpos) / (double)b_max;
retLpos = maxLpos - fileBlockId * (maxLpos - minLpos) / (double)b_max;
}
return fileLpos;
return retLpos;
}
uint64_t InterpolationFilePositionEstimator::determineEndBlock(const cta::common::dataStructures::TapeFile& file) const{
return file.blockId + (file.fileSize / c_blockSize) + 1;
}
void InterpolationFilePositionEstimator::checkMediaTypeConsistency(){
if(!m_mediaType.minLPos || !m_mediaType.maxLPos){
std::string errorMsg = "In InterpolationFilePositionEstimator::checkMediaTypeConsistency(), the media type (" + m_mediaType.name + ") associated to the tape does not give informations about the minLPos and maxLPos.";
throw cta::exception::Exception(errorMsg);
}
if(!m_mediaType.nbWraps){
std::string errorMsg = "In InterpolationFilePositionEstimator::checkMediaTypeConsistency(), the media type (" + m_mediaType.name + ") associated to the tape does not give informations about number of wraps the media contains.";
throw cta::exception::Exception(errorMsg);
}
}
}}}}
\ No newline at end of file
......@@ -28,11 +28,14 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
class InterpolationFilePositionEstimator : public FilePositionEstimator{
public:
InterpolationFilePositionEstimator(const std::vector<drive::endOfWrapPosition> & endOfWrapPositions, const cta::catalogue::MediaType & mediaType);
FilePosition getFilePosition(const cta::RetrieveJob& job) const override;
FilePositionInfos getFilePosition(const cta::RetrieveJob& job) const override;
virtual ~InterpolationFilePositionEstimator();
static const uint64_t c_blockSize = 256000;
private:
void checkMediaTypeConsistency();
Position getPhysicalPosition(const uint64_t blockId) const;
uint64_t determineWrapNb(const uint64_t blockId) const;
uint64_t determineLPos(const uint64_t blockId, const uint64_t wrapNumber) const;
......
......@@ -23,6 +23,21 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
Position::Position():m_wrap(0),m_lpos(0) {
}
Position::Position(const Position& other){
if(this != &other){
m_wrap = other.m_wrap;
m_lpos = other.m_lpos;
}
}
Position & Position::operator=(const Position& other){
if(this != &other){
m_wrap = other.m_wrap;
m_lpos = other.m_lpos;
}
return *this;
}
Position::~Position() {
}
......@@ -30,7 +45,7 @@ uint64_t Position::getLPos() const {
return m_lpos;
}
uint64_t Position::getWrap() const {
uint32_t Position::getWrap() const {
return m_wrap;
}
......@@ -38,7 +53,7 @@ void Position::setLPos(const uint64_t lpos) {
m_lpos = lpos;
}
void Position::setWrap(const uint64_t wrap) {
void Position::setWrap(const uint32_t wrap) {
m_wrap = wrap;
}
......
......@@ -25,13 +25,15 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
class Position {
public:
Position();
Position(const Position & other);
Position &operator=(const Position &other);
virtual ~Position();
uint64_t getWrap() const;
uint32_t getWrap() const;
uint64_t getLPos() const;
void setWrap(const uint64_t wrap);
void setWrap(const uint32_t wrap);
void setLPos(const uint64_t lpos);
private:
uint64_t m_wrap;
uint32_t m_wrap;
uint64_t m_lpos;
};
......
......@@ -34,5 +34,16 @@ namespace castor { namespace tape { namespace tapeserver { namespace rao {
uint64_t meanNbBlocksPerWrap = nbBlocksPerWrap / nbEndOfWrapPositions;
endOfWrapPositions[nbEndOfWrapPositions-1].blockId = endOfWrapPositions.at(nbEndOfWrapPositions-2).blockId + meanNbBlocksPerWrap;
}
uint8_t RAOHelpers::determineBand(uint32_t nbWrapsOnTape, uint32_t wrapNumber){
//As a tape has always 4 bands the following formula will give the band number to which the wrapNumber
//belongs to
return (wrapNumber / (nbWrapsOnTape / 4));
}
uint8_t RAOHelpers::determineLandingZone(uint64_t minTapeLPos, uint64_t maxTapeLpos, uint64_t fileLPos){
uint64_t mid = (maxTapeLpos - minTapeLPos) / 2;
return fileLPos < mid ? 0 : 1;
}
}}}}
\ No newline at end of file
......@@ -34,6 +34,10 @@ public:
*/
static void improveEndOfLastWrapPositionIfPossible(std::vector<drive::endOfWrapPosition> & endOfWrapPositions);
static uint8_t determineBand(uint32_t nbWrapsOnTape, uint32_t wrapNumber);
static uint8_t determineLandingZone(uint64_t minTapeLPos, uint64_t maxTapeLpos, uint64_t fileLPos);
};
}}}}
\ No newline at end of file
......@@ -44,6 +44,7 @@ namespace unitTests {
mediaType.name = "LTO7M";
mediaType.minLPos = 2696;
mediaType.maxLPos = 171097;
mediaType.nbWraps = 112;
return mediaType;
}
......@@ -93,7 +94,7 @@ namespace unitTests {
rao::InterpolationFilePositionEstimator estimator(eowPositions,mediaType);
{
std::unique_ptr<cta::RetrieveJob> retrieveJob = RAOTestEnvironment::createRetrieveJobForRAOTests(0,1,1,100000000);
rao::FilePosition positionFile = estimator.getFilePosition(*retrieveJob);
rao::FilePositionInfos positionFile = estimator.getFilePosition(*retrieveJob);
//The LPOS start position of the file should be equal to the minLPos of the LTO7 media type
rao::Position startPositionFile = positionFile.getStartPosition();
ASSERT_EQ(0,startPositionFile.getWrap());
......@@ -106,6 +107,11 @@ namespace unitTests {
uint64_t endPositionBlockId = jobTapeFile.blockId + (jobTapeFile.fileSize / rao::InterpolationFilePositionEstimator::c_blockSize) + 1;
uint64_t expectedEndPositionLPos = mediaType.minLPos.value() + endPositionBlockId * (mediaType.maxLPos.value() - mediaType.minLPos.value()) / eowPositions.at(0).blockId;
ASSERT_EQ(expectedEndPositionLPos,endPositionFile.getLPos());
ASSERT_EQ(0,positionFile.getStartBand());
ASSERT_EQ(0,positionFile.getEndBand());
ASSERT_EQ(0,positionFile.getStartLandingZone());
ASSERT_EQ(0,positionFile.getEndLandingZone());
}
}
......@@ -118,7 +124,7 @@ namespace unitTests {
{
//Now create a retrieve job that has a blockId greater than the first wrap end of wrap position
std::unique_ptr<cta::RetrieveJob> retrieveJob = RAOTestEnvironment::createRetrieveJobForRAOTests(210000,1,1,100000000);
rao::FilePosition positionFile = estimator.getFilePosition(*retrieveJob);
rao::FilePositionInfos positionFile = estimator.getFilePosition(*retrieveJob);
double b_max = (double) eowPositions.at(1).blockId - (double) eowPositions.at(0).blockId;
auto jobTapeFile = retrieveJob->selectedTapeFile();
uint64_t fileBlockId = jobTapeFile.blockId - eowPositions.at(0).blockId;
......@@ -132,6 +138,11 @@ namespace unitTests {
uint64_t endPositionBlockId = jobTapeFile.blockId + (jobTapeFile.fileSize / rao::InterpolationFilePositionEstimator::c_blockSize) + 1 - eowPositions.at(0).blockId;
uint64_t expectedEndPositionLPos = mediaType.maxLPos.value() - endPositionBlockId * (mediaType.maxLPos.value() - mediaType.minLPos.value()) / b_max;
ASSERT_EQ(expectedEndPositionLPos,endPositionFile.getLPos());
ASSERT_EQ(0,positionFile.getStartBand());
ASSERT_EQ(0,positionFile.getEndBand());
ASSERT_EQ(1,positionFile.getStartLandingZone());
ASSERT_EQ(1,positionFile.getEndLandingZone());
}
}
......
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