EnterpriseRAOAlgorithm.cpp 2.89 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2019  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/>.
 */

#include <list>

#include "EnterpriseRAOAlgorithm.hpp"
#include "castor/tape/tapeserver/SCSI/Structures.hpp"
23
#include "common/Timer.hpp"
24
25
26
27
28
29
30
31
32
33

namespace castor { namespace tape { namespace tapeserver { namespace rao {

EnterpriseRAOAlgorithm::EnterpriseRAOAlgorithm(castor::tape::tapeserver::drive::DriveInterface * drive, const uint64_t maxFilesSupported):m_drive(drive), m_maxFilesSupported(maxFilesSupported) {
}

EnterpriseRAOAlgorithm::~EnterpriseRAOAlgorithm() {
}

std::vector<uint64_t> EnterpriseRAOAlgorithm::performRAO(const std::vector<std::unique_ptr<cta::RetrieveJob> >& jobs) {
34
  cta::utils::Timer totalTimer;
35
36
  std::vector<uint64_t> raoOrder;
  uint64_t njobs = jobs.size();
37
  uint32_t block_size = c_blockSize;
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  std::list<castor::tape::SCSI::Structures::RAO::blockLims> files;
  for (uint32_t i = 0; i < njobs; i++) {
    cta::RetrieveJob *job = jobs.at(i).get();
    castor::tape::SCSI::Structures::RAO::blockLims lims;
    strncpy((char*)lims.fseq, std::to_string(i).c_str(), sizeof(i));
    lims.begin = job->selectedTapeFile().blockId;
    lims.end = job->selectedTapeFile().blockId + 8 +
               /* ceiling the number of blocks */
               ((job->archiveFile.fileSize + block_size - 1) / block_size);

    files.push_back(lims);
    if ((files.size() == m_maxFilesSupported) ||
            ((i == njobs - 1) && (files.size() > 1))) {
      /* We do a RAO query if:
       *  1. the maximum number of files supported by the drive
       *     for RAO query has been reached
       *  2. the end of the jobs list has been reached and there are at least
       *     2 unordered files
       */
      m_drive->queryRAO(files, m_maxFilesSupported);

      /* Add the RAO sorted files to the new list*/
      for (auto fit = files.begin(); fit != files.end(); fit++) {
        uint64_t id = atoi((char*)fit->fseq);
        raoOrder.push_back(id);
      }
      files.clear();
    }
  }
  for (auto fit = files.begin(); fit != files.end(); fit++) {
    uint64_t id = atoi((char*)fit->fseq);
    raoOrder.push_back(id);
  }
  files.clear();
72
  m_raoTimings.insertAndReset("RAOAlgorithmTime",totalTimer);
73
74
75
  return raoOrder;
}

76
77
78
std::string EnterpriseRAOAlgorithm::getName() const {
  return "enterprise";
}
79
80

}}}}