NCBI C++ ToolKit
job_status.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef NETSCHEDULE_JOB_STATUS__HPP
2 #define NETSCHEDULE_JOB_STATUS__HPP
3 
4 /* $Id: job_status.hpp 84210 2018-10-25 15:29:28Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Anatoliy Kuznetsov, Victor Joukov
30  *
31  * File Description:
32  * Net schedule job status states.
33  *
34  */
35 
36 /// @file job_status.hpp
37 /// NetSchedule job status tracker.
38 ///
39 /// @internal
40 
41 #include <map>
42 
43 #include <corelib/ncbimtx.hpp>
44 
45 #include "ns_types.hpp"
46 #include "ns_precise_time.hpp"
47 
48 
50 
51 class CJobGCRegistry;
52 
53 
63 const size_t
66 
67 
68 
69 // In-Memory storage to track status of all jobs
70 // Syncronized thread safe class
72 {
73 public:
74  typedef vector<TNSBitVector*> TStatusStorage;
75 
76 public:
79 
80  TJobStatus GetStatus(unsigned job_id) const;
81 
82  // Add closed interval of ids to pending status
83  void AddPendingBatch(unsigned job_id_from, unsigned job_id_to);
84 
85  // Provides a job id (or 0 if none) which is in the given state and is not
86  // in the unwanted jobs list
87  unsigned int GetJobByStatus(TJobStatus status,
88  const TNSBitVector & unwanted_jobs,
89  const TNSBitVector & restrict_jobs,
90  bool restricted) const;
91  unsigned int GetJobByStatus(const vector<TJobStatus> & statuses,
92  const TNSBitVector & unwanted_jobs,
93  const TNSBitVector & restrict_jobs,
94  bool restricted) const;
95 
96  void GetJobs(const vector<TJobStatus> & statuses,
97  TNSBitVector & jobs) const;
98  void GetJobs(TJobStatus status, TNSBitVector & jobs) const;
100  CNSPreciseTime timeout,
101  const CJobGCRegistry & gc_registry) const;
103  CNSPreciseTime timeout,
104  const TNSBitVector & read_jobs,
105  const CJobGCRegistry & gc_registry) const;
106 
107  // true if we have pending jobs
108  bool AnyPending() const;
109 
110  // Get next job in the specified status, or first if job_id is 0
111  unsigned GetNext(TJobStatus status, unsigned job_id) const;
112 
113  // Set job status without logic control.
114  // @param status
115  // Status to set (all other statuses are cleared)
116  // Non existing status code clears all statuses
117  void SetStatus(unsigned int job_id, TJobStatus status);
118 
119  void AddPendingJob(unsigned int job_id);
120 
121  // Erase the job
122  void Erase(unsigned job_id);
123 
124  // Set job status without any protection
125  void SetExactStatusNoLock(unsigned int job_id, TJobStatus status,
126  bool set_clear);
127 
128  // Return number of jobs in specified status/statuses
129  unsigned int CountStatus(TJobStatus status) const;
130  unsigned int CountStatus(const vector<TJobStatus> & statuses) const;
131  vector<unsigned int>
132  GetJobCounters(const vector<TJobStatus> & statuses) const;
133 
134  // Count all jobs in any status
135  unsigned int Count(void) const;
136  unsigned int GetMinJobID(void) const;
137 
138  bool AnyJobs(void) const;
139  bool AnyJobs(TJobStatus status) const;
140  bool AnyJobs(const vector<TJobStatus> & statuses) const;
141 
142  void StatusStatistics(TJobStatus status,
143  TNSBitVector::statistics* st) const;
144 
145  // Clear status storage
146  void ClearAll(TNSBitVector* bv);
147  void ClearAll(void);
148 
149  // Optimize bitvectors memory
150  void OptimizeMem();
151 
152 private:
153  void x_IncDoneJobs(void);
154 
155 private:
158 
159 private:
161  mutable CRWLock m_Lock;
162 
163  // Done jobs counter
164  unsigned m_DoneCnt;
165 };
166 
167 
169 
170 #endif /* NETSCHEDULE_JOB_STATUS__HPP */
171 
unsigned GetNext(TJobStatus status, unsigned job_id) const
Definition: job_status.cpp:465
void SetStatus(unsigned int job_id, TJobStatus status)
Definition: job_status.cpp:194
TStatusStorage m_StatusStor
Definition: job_status.hpp:160
void Erase(unsigned job_id)
Definition: job_status.cpp:226
void GetJobs(const vector< TJobStatus > &statuses, TNSBitVector &jobs) const
Definition: job_status.cpp:340
void AddPendingJob(unsigned int job_id)
Definition: job_status.cpp:219
void StatusStatistics(TJobStatus status, TNSBitVector::statistics *st) const
Definition: job_status.cpp:183
bool AnyPending() const
Definition: job_status.cpp:456
vector< unsigned int > GetJobCounters(const vector< TJobStatus > &statuses) const
Definition: job_status.cpp:103
void SetExactStatusNoLock(unsigned int job_id, TJobStatus status, bool set_clear)
Definition: job_status.cpp:267
unsigned int GetMinJobID(void) const
Definition: job_status.cpp:128
CJobStatusTracker & operator=(const CJobStatusTracker &)
CJobStatusTracker(const CJobStatusTracker &)
unsigned int CountStatus(TJobStatus status) const
Definition: job_status.cpp:80
void x_IncDoneJobs(void)
Definition: job_status.cpp:474
bool AnyJobs(void) const
Definition: job_status.cpp:150
TJobStatus GetStatus(unsigned job_id) const
Definition: job_status.cpp:66
TNSBitVector GetOutdatedReadVacantJobs(CNSPreciseTime timeout, const TNSBitVector &read_jobs, const CJobGCRegistry &gc_registry) const
Definition: job_status.cpp:405
void AddPendingBatch(unsigned job_id_from, unsigned job_id_to)
Definition: job_status.cpp:276
vector< TNSBitVector * > TStatusStorage
Definition: job_status.hpp:74
unsigned int GetJobByStatus(TJobStatus status, const TNSBitVector &unwanted_jobs, const TNSBitVector &restrict_jobs, bool restricted) const
Definition: job_status.cpp:286
TNSBitVector GetOutdatedPendingJobs(CNSPreciseTime timeout, const CJobGCRegistry &gc_registry) const
Definition: job_status.cpp:361
unsigned int Count(void) const
Definition: job_status.cpp:116
void ClearAll(void)
Definition: job_status.cpp:245
CRWLock –.
Definition: ncbimtx.hpp:953
Bitvector Bit-vector container with runtime compression of bits.
Definition: bm.h:115
EJobStatus
Job status codes.
@ eDone
Job is ready (computed successfully)
@ eConfirmed
Final state - read confirmed.
@ eReading
Job has its output been reading.
@ eCanceled
Explicitly canceled.
@ eRunning
Running on a worker node.
@ ePending
Waiting for execution.
@ eReadFailed
Final state - read failed.
@ eFailed
Failed to run (execution timeout)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const size_t g_ValidJobStatusesSize
Definition: job_status.hpp:64
const CNetScheduleAPI::EJobStatus g_ValidJobStatuses[]
Definition: job_status.hpp:55
Multi-threading – mutexes; rw-locks; semaphore.
Statistical information about bitset's memory allocation details.
Definition: bm.h:125
Modified on Sun Jul 14 04:59:24 2024 by modify_doxy.py rev. 669887