diff --git a/scheduler/OStoreDB/OStoreDB.cpp b/scheduler/OStoreDB/OStoreDB.cpp index 0db1c68d309cf19952a05f0d05877fac8b565a38..a46f203726b773e4f1e1f7e7e32ad22224571b72 100644 --- a/scheduler/OStoreDB/OStoreDB.cpp +++ b/scheduler/OStoreDB/OStoreDB.cpp @@ -509,38 +509,80 @@ OStoreDB::ArchiveToFileRequestCancelation::~ArchiveToFileRequestCancelation() { // QueueItor::QueueItor //------------------------------------------------------------------------------ template<> -QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue::JobDump>:: +QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue>:: QueueItor(objectstore::Backend &objectStore, const std::string &tapePoolName) : m_objectStore(objectStore), - m_tapePoolName(tapePoolName) + m_onlyThisTapePool(!tapePoolName.empty()) { objectstore::RootEntry re(m_objectStore); objectstore::ScopedSharedLock rel(re); re.fetch(); m_jobQueuesQueue = re.dumpArchiveQueues(); rel.release(); + + // Find the first queue m_jobQueuesQueueIt = m_jobQueuesQueue.begin(); + + // If we specified a tape pool, advance to the correct queue + if(m_onlyThisTapePool) { + for( ; m_jobQueuesQueueIt != m_jobQueuesQueue.end(); ++m_jobQueuesQueueIt) { + if(m_jobQueuesQueueIt->tapePool == tapePoolName) { + break; + } + } + } + + // Find the first job in the queue + if(m_jobQueuesQueueIt != m_jobQueuesQueue.end()) { + getQueueJobs(); + } } -#if 0 //------------------------------------------------------------------------------ -// OStoreDB::getArchiveQueueJobs() +// QueueItor::getQueueJobs //------------------------------------------------------------------------------ -std::list<objectstore::ArchiveQueue::JobDump> OStoreDB::getArchiveQueueJobs(const std::string &address) const +template<typename JobQueuesQueue, typename JobQueue> +void QueueItor<JobQueuesQueue, JobQueue>:: +getQueueJobs() { - objectstore::ArchiveQueue osaq(address, m_objectStore); - ScopedSharedLock ostpl(osaq); // released when it goes out of scope - osaq.fetch(); - return osaq.dumpJobs(); + JobQueue osaq(m_jobQueuesQueueIt->address, m_objectStore); + ScopedSharedLock ostpl(osaq); + osaq.fetch(); + m_jobQueue = osaq.dumpJobs(); + ostpl.release(); + m_jobQueueIt = m_jobQueue.begin(); +} + +//------------------------------------------------------------------------------ +// QueueItor::end +//------------------------------------------------------------------------------ +template<> +bool QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue>:: +end() { + // Case 1: no more queues + if(m_jobQueuesQueueIt == m_jobQueuesQueue.end()) return true; + + // Case 2: we are in a queue and haven't reached the end of it + if(m_jobQueueIt != m_jobQueue.end()) return false; + + // Case 3: we have reached the end of the current queue and this is the only queue we care about + if(m_onlyThisTapePool) return true; + + // Case 4: we have reached the end of the current queue, try to advance to the next queue + for(++m_jobQueuesQueueIt; m_jobQueuesQueueIt != m_jobQueuesQueue.end(); ++m_jobQueuesQueueIt) { + getQueueJobs(); + if(m_jobQueueIt != m_jobQueue.end()) break; + } + return m_jobQueueIt == m_jobQueue.end(); } -#endif //------------------------------------------------------------------------------ // OStoreDB::getArchiveJobList() //------------------------------------------------------------------------------ -void OStoreDB::getArchiveJobList(QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue::JobDump> &q_it, +void OStoreDB::getArchiveJobList(QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue> &q_it, std::list<cta::common::dataStructures::ArchiveJob> &archiveJobList) const { +#if 0 objectstore::ArchiveRequest osar(ar->address, m_objectStore); ScopedSharedLock osarl(osar); osar.fetch(); @@ -571,6 +613,7 @@ void OStoreDB::getArchiveJobList(QueueItor<objectstore::RootEntry::ArchiveQueueD archiveJobList.back().request.srcURL = osar.getSrcURL(); archiveJobList.back().request.archiveReportURL = osar.getArchiveReportURL(); archiveJobList.back().request.storageClass = osar.getArchiveFile().storageClass; +#endif } //------------------------------------------------------------------------------ @@ -581,7 +624,7 @@ std::list<cta::common::dataStructures::ArchiveJob> { std::list<cta::common::dataStructures::ArchiveJob> ret; - QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue::JobDump> + QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue> q_it(m_objectStore, tapePoolName); while(!q_it.end()) { @@ -613,7 +656,7 @@ std::map<std::string, std::list<common::dataStructures::ArchiveJob> > std::map<std::string, std::list<common::dataStructures::ArchiveJob>> ret; - QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue::JobDump> + QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue> q_it(m_objectStore); while(!q_it.end()) { diff --git a/scheduler/OStoreDB/OStoreDB.hpp b/scheduler/OStoreDB/OStoreDB.hpp index a0c5dc6ff5eea07874364188e93886e2f5a33eab..32a01a1d33790768a14e030e3a62d2c2325f1a7d 100644 --- a/scheduler/OStoreDB/OStoreDB.hpp +++ b/scheduler/OStoreDB/OStoreDB.hpp @@ -53,14 +53,17 @@ template<typename JobQueuesQueue, typename JobQueue> class QueueItor { public: QueueItor(objectstore::Backend &objectStore, const std::string &tapePoolName = ""); - bool end() const; - const std::string &tapePool() { return m_jobQueuesQueueIt->tapePool; } + bool end(); + const std::string &tapePool() const { return m_jobQueuesQueueIt->tapePool; } private: - objectstore::Backend &m_objectStore; - std::string m_tapePoolName; - typename std::list<JobQueuesQueue> m_jobQueuesQueue; - typename std::list<JobQueuesQueue>::const_iterator m_jobQueuesQueueIt; - typename std::list<JobQueue>::const_iterator m_jobQueueIt; + void getQueueJobs(); + + objectstore::Backend &m_objectStore; // Reference to ObjectStore Backend + bool m_onlyThisTapePool; // true if a tapePoolName parameter was passed to the constructor + typename std::list<JobQueuesQueue> m_jobQueuesQueue; // list of Archive or Retrieve Job Queues + typename std::list<JobQueuesQueue>::const_iterator m_jobQueuesQueueIt; // iterator across m_jobQueuesQueue + typename std::list<typename JobQueue::JobDump> m_jobQueue; // list of Archive or Retrieve Jobs + typename std::list<typename JobQueue::JobDump>::const_iterator m_jobQueueIt; // iterator across m_jobQueue }; class OStoreDB: public SchedulerDatabase { @@ -301,7 +304,7 @@ public: */ private: /** Obtain the list of archive jobs from the specified archive queue */ - void getArchiveJobList(QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue::JobDump> &q_it, + void getArchiveJobList(QueueItor<objectstore::RootEntry::ArchiveQueueDump, objectstore::ArchiveQueue> &q_it, std::list<cta::common::dataStructures::ArchiveJob> &archiveJobList) const; /** Collection of smaller scale parts of reportDriveStatus */