NCBI C++ ToolKit
ns_rollback.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ns_rollback.cpp 84210 2018-10-25 15:29:28Z satskyse $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Sergey Satskiy
27  *
28  * File Description:
29  * NetSchedule limited rollback support
30  *
31  */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistl.hpp>
35 
36 #include "ns_rollback.hpp"
37 #include "ns_queue.hpp"
38 
39 
41 
42 
44 {
46 
47  ERR_POST(Warning << "Cancelling the submitted job due to "
48  "a network error while reporting the job key. "
49  "Time to write to memory: "
51  << " sec. Time on socket write: "
53  << " sec.");
54 
55  try {
56  CJob job; // Not used here
57 
58  // true -> it is a cancel due to rollback
59  queue->Cancel(m_Client, m_JobId, queue->MakeJobKey(m_JobId), job, true);
60  } catch (const exception & ex) {
61  ERR_POST("Error while rolling back job submission: " << ex.what());
62  } catch (...) {
63  ERR_POST("Unknown error while rolling back job submission.");
64  }
65 }
66 
67 
69 {
70  ERR_POST(Warning << "Cancelling the submitted job batch due to "
71  "a network error while reporting the job keys.");
72 
73  try {
74  for (size_t k = 0; k < m_BatchSize; ++k) {
75  CJob job; // Not used here
76 
77  // true -> it is a cancel due to rollback
78  queue->Cancel(m_Client, m_FirstJobId + k,
79  queue->MakeJobKey(m_FirstJobId + k), job, true);
80  }
81  } catch (const exception & ex) {
82  ERR_POST("Error while rolling back job batch submission: " << ex.what());
83  } catch (...) {
84  ERR_POST("Unknown error while rolling back job batch submission");
85  }
86 }
87 
88 
90 {
91  ERR_POST(Warning << "Rolling back job request due to "
92  "a network error while reporting the job key.");
93 
94  // It is basically the same as returning a job but without putting the job
95  // into a blacklist.
96  try {
97  string warning; // used for auth tokens only, so
98  // not analyzed here
99  CJob job; // Not used here
100 
101  // true -> returned due to rollback
102  queue->ReturnJob(m_Client, m_JobId, queue->MakeJobKey(m_JobId),
103  job, "", warning, CQueue::eRollback);
104  } catch (const exception & ex) {
105  ERR_POST("Error while rolling back requested job: " << ex.what());
106  } catch (...) {
107  ERR_POST("Unknown error while rolling back requested job");
108  }
109 }
110 
111 
113 {
114  ERR_POST(Warning << "Rolling back reading job request due to "
115  "a network error while reporting the job key.");
116 
117  // It is the same as read rollback but without putting the job
118  // into the reading blacklist
119  try {
120  CJob job; // Not used here
121 
122  // true -> returned due to rollback
124  job, "", true, false, m_PreviousStatus);
125  } catch (const exception & ex) {
126  ERR_POST("Error while rolling back read requested job: " << ex.what());
127  } catch (...) {
128  ERR_POST("Unknown error while rolling back read requested job");
129  }
130 }
131 
132 
134 
Definition: job.hpp:183
unsigned int m_FirstJobId
Definition: ns_rollback.hpp:98
virtual void Rollback(CQueue *queue)
Definition: ns_rollback.cpp:68
virtual void Rollback(CQueue *queue)
Definition: ns_rollback.cpp:89
CNSClientId m_Client
unsigned int m_JobId
static CNSPreciseTime Current(void)
TJobStatus m_PreviousStatus
virtual void Rollback(CQueue *queue)
CNSClientId m_Client
unsigned int m_JobId
CNSPreciseTime m_OpBegin
Definition: ns_rollback.hpp:75
unsigned int m_JobId
Definition: ns_rollback.hpp:74
CNSPreciseTime m_WrittenToDB
Definition: ns_rollback.hpp:76
CNSClientId m_Client
Definition: ns_rollback.hpp:73
virtual void Rollback(CQueue *queue)
Definition: ns_rollback.cpp:43
TJobStatus ReturnReadingJob(const CNSClientId &client, unsigned int job_id, const string &job_key, CJob &job, const string &auth_token, bool is_ns_rollback, bool blacklist, TJobStatus target_status)
Definition: ns_queue.cpp:2226
string MakeJobKey(unsigned int job_id) const
Definition: ns_queue.cpp:4046
@ eRollback
Definition: ns_queue.hpp:100
TJobStatus ReturnJob(const CNSClientId &client, unsigned int job_id, const string &job_key, CJob &job, const string &auth_token, string &warning, TJobReturnOption how)
Definition: ns_queue.cpp:1357
TJobStatus Cancel(const CNSClientId &client, unsigned int job_id, const string &job_key, CJob &job, bool is_ns_rollback=false)
Definition: ns_queue.cpp:1673
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
The NCBI C++/STL use hints.
string NS_FormatPreciseTimeAsSec(const CNSPreciseTime &t)
Modified on Mon May 20 05:05:54 2024 by modify_doxy.py rev. 669887