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

Go to the SVN repository for this file.

1 /* $Id: dbapi_driver_exception_storage.cpp 84488 2018-11-14 15:43:43Z 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  * Author: Sergey Sikorskiy
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <dbapi/error_codes.hpp>
34 
36 
37 
38 #define NCBI_USE_ERRCODE_X Dbapi_DrvrUtil
39 
41 
42 namespace impl
43 {
44 
45 /////////////////////////////////////////////////////////////////////////////
46 struct SNoLock
47 {
48  void operator() (CDB_UserHandler::TExceptions& /*resource*/) const {}
49 };
50 
51 struct SUnLock
52 {
54  {
56  }
57 };
58 
59 /////////////////////////////////////////////////////////////////////////////
61  : m_ClosingConnect(false),
62  m_Retriable(eRetriable_Unknown),
63  m_HasTimeout(false)
64 {
65 }
66 
67 
69 {
70  try {
72  delete *it;
73  }
74  }
76 }
77 
78 
79 void CDBExceptionStorage::Accept(unique_ptr<CDB_Exception>& e)
80 {
81  static const size_t kMaxItemsToCheck = 3;
82 
84 
85  // Note 1:
86  // Sometimes the very same exception is pushed to the storage via different
87  // paths. To avoid double output in a log file the accumulated list is
88  // checked if there is this exception here already.
89  // Note 2:
90  // There are some cases though when the exception storage is used not for
91  // the exceptions but for passing data. Sometimes there a lot of data and
92  // checking the whole container introduces severe performance penalties. To
93  // avoid them the only limited number of the latest items is checked.
94  size_t checked_items = 0;
95  for (auto it = m_Exceptions.rbegin();
96  checked_items < kMaxItemsToCheck && it != m_Exceptions.rend();
97  ++it) {
98  if ((*it)->GetDBErrCode() == e->GetDBErrCode())
99  if ((*it)->GetMsg() == e->GetMsg())
100  return; // the same exception has already been registered
101  ++checked_items;
102  }
103 
104  CDB_Exception * raw_pointer = e.get();
105  m_Exceptions.push_back(raw_pointer);
106  e.release();
107 
108  const CDB_TimeoutEx * timeout_exc =
109  dynamic_cast<const CDB_TimeoutEx *>(raw_pointer);
110  if (timeout_exc)
111  m_HasTimeout = true;
112 }
113 
114 
116  const CDB_Exception::SContext* dbg_info,
117  const CConnection* conn,
118  const CDBParams* par)
119 {
121 
122  if (!m_Exceptions.empty()) {
124  TGuard guard(m_Exceptions);
125 
126  ERetriable retriable = m_Retriable;
128 
129  m_HasTimeout = false;
130 
131  try {
132  handler.HandleExceptions(m_Exceptions, dbg_info, conn, par);
133  } catch (CException & exc) {
134  exc.SetRetriable(retriable);
135  throw;
136  }
137  }
138 }
139 
141 {
142  if (m_Retriable == eRetriable_No)
143  return;
144  m_Retriable = retriable;
145 }
146 
147 }
148 
149 void s_DelExceptionStorage(impl::CDBExceptionStorage* storage, void* /* data */)
150 {
151  delete storage;
152 }
153 
155 
CDBParams.
Definition: interfaces.hpp:154
CDB_Exception –.
Definition: exception.hpp:118
void Handle(const CDBHandlerStack &handler)
void Accept(unique_ptr< CDB_Exception > &e)
CDB_UserHandler::TExceptions m_Exceptions
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
void s_DelExceptionStorage(impl::CDBExceptionStorage *storage, void *)
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
#define false
Definition: bool.h:36
ERetriable
Can the action be retried?
Definition: ncbimisc.hpp:167
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
@ eRetriable_Unknown
It is unknown if the action can succeed if retried.
Definition: ncbimisc.hpp:169
@ eRetriable_No
It makes no sense to retry the action.
Definition: ncbimisc.hpp:168
static void ClearExceptions(TExceptions &expts)
Definition: exception.cpp:606
deque< CDB_Exception * > TExceptions
Exception container type.
Definition: exception.hpp:574
#define NCBI_CURRENT_FUNCTION
Get current function name.
Definition: ncbidiag.hpp:142
void SetRetriable(ERetriable retriable)
Set the info about ability to retry an action caused the exception.
Definition: ncbiexpt.hpp:1062
#define NCBI_CATCH_ALL_X(err_subcode, message)
Definition: ncbiexpt.hpp:619
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
void operator()(CDB_UserHandler::TExceptions &) const
void operator()(CDB_UserHandler::TExceptions &resource) const
Modified on Sun Jul 21 04:15:05 2024 by modify_doxy.py rev. 669887