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

Go to the SVN repository for this file.

1 /* $Id: bdb_checkpoint_thread.cpp 91315 2020-10-08 18:28:17Z grichenk $
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: Anatoliy Kuznetsov
27  *
28  * File Description: Transaction checkpoint / memptrickle thread
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
35 #include <db/bdb/bdb_env.hpp>
36 
37 #include <db/error_codes.hpp>
38 
40 
41 
42 #define NCBI_USE_ERRCODE_X Db_Bdb_Checkpoint
43 
45 
46 
47 
49  int memp_trickle,
50  unsigned run_delay,
51  unsigned stop_request_poll)
52 : CThreadNonStop(run_delay, stop_request_poll),
53  m_Env(env),
54  m_MempTrickle(memp_trickle),
55  m_ErrCnt(0),
56  m_MaxErrors(100)
57 {
61 }
62 
64 {
65 // LOG_POST_X(1, "~CBDB_CheckPointThread()");
66 }
67 
68 
70 {
71  m_MaxErrors = max_err;
72 }
73 
75 {
76  try {
77  if (m_Env.IsTransactional() &&
79  {
80  LOG_POST(Info << "Running transaction checkpoint");
82  }
83 
84  if (m_MempTrickle &&
86  int nwrotep = 0;
87  m_Env.MempTrickle(m_MempTrickle, &nwrotep);
88  if (nwrotep) {
89  LOG_POST_X(2, Info << "CBDB_CheckPointThread::DoJob(): trickled "
90  << nwrotep << " pages");
91  }
92  }
95  }
96  }
97  catch (CBDB_ErrnoException& ex)
98  {
99  if (m_MaxErrors) {
100  ++m_ErrCnt;
101  }
102  if (ex.IsRecovery()) {
103  // fatal database error, stop right now!
104  RequestStop();
105  string msg ="Fatal Berkeley DB error: DB_RUNRECOVERY."
106  " Checkpoint thread has been stopped.";
107  ERR_POST_X(3, Error << msg);
108  } else {
109  ERR_POST_X(4, Error << "Error in checkpoint thread(supressed) "
110  << ex.what());
111  }
112 
113  if (m_ErrCnt > m_MaxErrors) {
114  RequestStop();
115  ERR_POST_X(5, Error <<
116  "Checkpoint thread has been stopped (too many errors)");
117  }
118  }
119  catch(exception& ex)
120  {
121  if (m_MaxErrors) {
122  ++m_ErrCnt;
123  }
124  ERR_POST_X(6, Error << "Error in checkpoint thread: "
125  << ex.what());
126 
127  if (m_ErrCnt > m_MaxErrors) {
128  RequestStop();
129  ERR_POST_X(7, Error <<
130  "Checkpoint thread has been stopped (too many errors)");
131  }
132  }
133 }
134 
135 
136 
138 
Wrapper around Berkeley DB environment structure.
BDB environment object a collection including support for some or all of caching, locking,...
Definition: bdb_env.hpp:61
BDB errno exception class.
Definition: bdb_expt.hpp:84
Adaptation of CThread class repeatedly running some job.
void RequestStop()
Schedule thread Stop.
static HENV env
Definition: transaction2.c:38
CBDB_Env::TBackgroundFlags m_Flags
CBDB_CheckPointThread(CBDB_Env &env, int memp_trickle, unsigned run_delay, unsigned stop_request_poll=10)
void TransactionCheckpoint()
Flush the underlying memory pools, logs and data bases.
Definition: bdb_env.cpp:664
virtual void DoJob(void)
Payload function.
void DeadLockDetect()
Run deadlock detector.
Definition: bdb_env.cpp:1052
void MempTrickle(int percent, int *nwrotep)
Ensures that a specified percent of the pages in the shared memory pool are clean,...
Definition: bdb_env.cpp:962
void SetMaxErrors(unsigned max_err)
Set maximum number of errors this thread tolerates 0 - unlimited.
bool IsTransactional() const
Return TRUE if environment has been open as transactional.
Definition: bdb_env.cpp:683
bool IsRecovery() const
If it is DB_RUNRECOVERY error.
Definition: bdb_expt.cpp:81
@ eBackground_DeadLockDetect
Definition: bdb_env.hpp:374
@ eBackground_MempTrickle
Definition: bdb_env.hpp:372
@ eBackground_Checkpoint
Definition: bdb_env.hpp:373
#define LOG_POST_X(err_subcode, message)
Definition: ncbidiag.hpp:553
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
#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 bdb library (bdb.lib and ncbi_xcache_bdb.lib).
Modified on Tue Jun 18 13:35:58 2024 by modify_doxy.py rev. 669887