PageRenderTime 27ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/SN-NG4.2-db_4.8.30_import/db4/cxx/cxx_env.cpp

https://gitlab.com/OpenSourceMirror/sourcenav
C++ | 1217 lines | 939 code | 171 blank | 107 comment | 123 complexity | 83ae5731218dc02479b4e4a86eb683ff MD5 | raw file
  1. /*-
  2. * See the file LICENSE for redistribution information.
  3. *
  4. * Copyright (c) 1997-2009 Oracle. All rights reserved.
  5. *
  6. * $Id$
  7. */
  8. #include "db_config.h"
  9. #include "db_int.h"
  10. #include "db_cxx.h"
  11. #include "dbinc/cxx_int.h"
  12. #include "dbinc/db_page.h"
  13. #include "dbinc/db_am.h"
  14. #include "dbinc/log.h"
  15. #include "dbinc_auto/common_ext.h"
  16. #include "dbinc_auto/log_ext.h"
  17. #ifdef HAVE_CXX_STDHEADERS
  18. using std::cerr;
  19. #endif
  20. // Helper macros for simple methods that pass through to the
  21. // underlying C method. They may return an error or raise an exception.
  22. // These macros expect that input _argspec is an argument
  23. // list element (e.g., "char *arg") and that _arglist is the arguments
  24. // that should be passed through to the C method (e.g., "(dbenv, arg)")
  25. //
  26. #define DBENV_METHOD_ERR(_name, _argspec, _arglist, _on_err) \
  27. int DbEnv::_name _argspec \
  28. { \
  29. DB_ENV *dbenv = unwrap(this); \
  30. int ret; \
  31. \
  32. if ((ret = dbenv->_name _arglist) != 0) { \
  33. _on_err; \
  34. } \
  35. return (ret); \
  36. }
  37. #define DBENV_METHOD(_name, _argspec, _arglist) \
  38. DBENV_METHOD_ERR(_name, _argspec, _arglist, \
  39. DB_ERROR(this, "DbEnv::" # _name, ret, error_policy()))
  40. #define DBENV_METHOD_QUIET(_name, _argspec, _arglist) \
  41. int DbEnv::_name _argspec \
  42. { \
  43. DB_ENV *dbenv = unwrap(this); \
  44. \
  45. return (dbenv->_name _arglist); \
  46. }
  47. #define DBENV_METHOD_VOID(_name, _argspec, _arglist) \
  48. void DbEnv::_name _argspec \
  49. { \
  50. DB_ENV *dbenv = unwrap(this); \
  51. \
  52. dbenv->_name _arglist; \
  53. }
  54. // The reason for a static variable is that some structures
  55. // (like Dbts) have no connection to any Db or DbEnv, so when
  56. // errors occur in their methods, we must have some reasonable
  57. // way to determine whether to throw or return errors.
  58. //
  59. // This variable is taken from flags whenever a DbEnv is constructed.
  60. // Normally there is only one DbEnv per program, and even if not,
  61. // there is typically a single policy of throwing or returning.
  62. //
  63. static int last_known_error_policy = ON_ERROR_UNKNOWN;
  64. // These 'glue' function are declared as extern "C" so they will
  65. // be compatible with picky compilers that do not allow mixing
  66. // of function pointers to 'C' functions with function pointers
  67. // to C++ functions.
  68. //
  69. extern "C"
  70. void _feedback_intercept_c(DB_ENV *dbenv, int opcode, int pct)
  71. {
  72. DbEnv::_feedback_intercept(dbenv, opcode, pct);
  73. }
  74. extern "C"
  75. void _paniccall_intercept_c(DB_ENV *dbenv, int errval)
  76. {
  77. DbEnv::_paniccall_intercept(dbenv, errval);
  78. }
  79. extern "C"
  80. void _event_func_intercept_c(DB_ENV *dbenv, u_int32_t event, void *event_info)
  81. {
  82. DbEnv::_event_func_intercept(dbenv, event, event_info);
  83. }
  84. extern "C"
  85. void _stream_error_function_c(const DB_ENV *dbenv,
  86. const char *prefix, const char *message)
  87. {
  88. DbEnv::_stream_error_function(dbenv, prefix, message);
  89. }
  90. extern "C"
  91. void _stream_message_function_c(const DB_ENV *dbenv, const char *message)
  92. {
  93. DbEnv::_stream_message_function(dbenv, message);
  94. }
  95. extern "C"
  96. int _app_dispatch_intercept_c(DB_ENV *dbenv, DBT *dbt, DB_LSN *lsn, db_recops op)
  97. {
  98. return (DbEnv::_app_dispatch_intercept(dbenv, dbt, lsn, op));
  99. }
  100. extern "C"
  101. int _rep_send_intercept_c(DB_ENV *dbenv, const DBT *cntrl, const DBT *data,
  102. const DB_LSN *lsn, int id, u_int32_t flags)
  103. {
  104. return (DbEnv::_rep_send_intercept(dbenv,
  105. cntrl, data, lsn, id, flags));
  106. }
  107. extern "C"
  108. int _isalive_intercept_c(
  109. DB_ENV *dbenv, pid_t pid, db_threadid_t thrid, u_int32_t flags)
  110. {
  111. return (DbEnv::_isalive_intercept(dbenv, pid, thrid, flags));
  112. }
  113. extern "C"
  114. void _thread_id_intercept_c(DB_ENV *dbenv, pid_t *pidp, db_threadid_t *thridp)
  115. {
  116. DbEnv::_thread_id_intercept(dbenv, pidp, thridp);
  117. }
  118. extern "C"
  119. char *_thread_id_string_intercept_c(DB_ENV *dbenv, pid_t pid,
  120. db_threadid_t thrid, char *buf)
  121. {
  122. return (DbEnv::_thread_id_string_intercept(dbenv, pid, thrid, buf));
  123. }
  124. void DbEnv::_feedback_intercept(DB_ENV *dbenv, int opcode, int pct)
  125. {
  126. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  127. if (cxxenv == 0) {
  128. DB_ERROR(0,
  129. "DbEnv::feedback_callback", EINVAL, ON_ERROR_UNKNOWN);
  130. return;
  131. }
  132. if (cxxenv->feedback_callback_ == 0) {
  133. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  134. "DbEnv::feedback_callback", EINVAL, cxxenv->error_policy());
  135. return;
  136. }
  137. (*cxxenv->feedback_callback_)(cxxenv, opcode, pct);
  138. }
  139. void DbEnv::_paniccall_intercept(DB_ENV *dbenv, int errval)
  140. {
  141. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  142. if (cxxenv == 0) {
  143. DB_ERROR(0,
  144. "DbEnv::paniccall_callback", EINVAL, ON_ERROR_UNKNOWN);
  145. return;
  146. }
  147. if (cxxenv->paniccall_callback_ == 0) {
  148. DB_ERROR(cxxenv, "DbEnv::paniccall_callback", EINVAL,
  149. cxxenv->error_policy());
  150. return;
  151. }
  152. (*cxxenv->paniccall_callback_)(cxxenv, errval);
  153. }
  154. void DbEnv::_event_func_intercept(
  155. DB_ENV *dbenv, u_int32_t event, void *event_info)
  156. {
  157. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  158. if (cxxenv == 0) {
  159. DB_ERROR(0,
  160. "DbEnv::event_func_callback", EINVAL, ON_ERROR_UNKNOWN);
  161. return;
  162. }
  163. if (cxxenv->event_func_callback_ == 0) {
  164. DB_ERROR(cxxenv, "DbEnv::event_func_callback", EINVAL,
  165. cxxenv->error_policy());
  166. return;
  167. }
  168. (*cxxenv->event_func_callback_)(cxxenv, event, event_info);
  169. }
  170. int DbEnv::_app_dispatch_intercept(DB_ENV *dbenv, DBT *dbt, DB_LSN *lsn,
  171. db_recops op)
  172. {
  173. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  174. if (cxxenv == 0) {
  175. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  176. "DbEnv::app_dispatch_callback", EINVAL, ON_ERROR_UNKNOWN);
  177. return (EINVAL);
  178. }
  179. if (cxxenv->app_dispatch_callback_ == 0) {
  180. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  181. "DbEnv::app_dispatch_callback", EINVAL,
  182. cxxenv->error_policy());
  183. return (EINVAL);
  184. }
  185. Dbt *cxxdbt = (Dbt *)dbt;
  186. DbLsn *cxxlsn = (DbLsn *)lsn;
  187. return ((*cxxenv->app_dispatch_callback_)(cxxenv, cxxdbt, cxxlsn, op));
  188. }
  189. int DbEnv::_isalive_intercept(
  190. DB_ENV *dbenv, pid_t pid, db_threadid_t thrid, u_int32_t flags)
  191. {
  192. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  193. if (cxxenv == 0) {
  194. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  195. "DbEnv::isalive_callback", EINVAL, ON_ERROR_UNKNOWN);
  196. return (0);
  197. }
  198. return ((*cxxenv->isalive_callback_)(cxxenv, pid, thrid, flags));
  199. }
  200. int DbEnv::_rep_send_intercept(DB_ENV *dbenv, const DBT *cntrl, const DBT *data,
  201. const DB_LSN *lsn, int id, u_int32_t flags)
  202. {
  203. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  204. if (cxxenv == 0) {
  205. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  206. "DbEnv::rep_send_callback", EINVAL, ON_ERROR_UNKNOWN);
  207. return (EINVAL);
  208. }
  209. const Dbt *cxxcntrl = (const Dbt *)cntrl;
  210. const DbLsn *cxxlsn = (const DbLsn *)lsn;
  211. Dbt *cxxdata = (Dbt *)data;
  212. return ((*cxxenv->rep_send_callback_)(cxxenv,
  213. cxxcntrl, cxxdata, cxxlsn, id, flags));
  214. }
  215. void DbEnv::_thread_id_intercept(DB_ENV *dbenv,
  216. pid_t *pidp, db_threadid_t *thridp)
  217. {
  218. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  219. if (cxxenv == 0) {
  220. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  221. "DbEnv::thread_id_callback", EINVAL, ON_ERROR_UNKNOWN);
  222. } else
  223. cxxenv->thread_id_callback_(cxxenv, pidp, thridp);
  224. }
  225. char *DbEnv::_thread_id_string_intercept(DB_ENV *dbenv,
  226. pid_t pid, db_threadid_t thrid, char *buf)
  227. {
  228. DbEnv *cxxenv = DbEnv::get_DbEnv(dbenv);
  229. if (cxxenv == 0) {
  230. DB_ERROR(DbEnv::get_DbEnv(dbenv),
  231. "DbEnv::thread_id_string_callback", EINVAL,
  232. ON_ERROR_UNKNOWN);
  233. return (NULL);
  234. }
  235. return (cxxenv->thread_id_string_callback_(cxxenv, pid, thrid, buf));
  236. }
  237. // A truism for the DbEnv object is that there is a valid
  238. // DB_ENV handle from the constructor until close().
  239. // After the close, the DB_ENV handle is invalid and
  240. // no operations are permitted on the DbEnv (other than
  241. // destructor). Leaving the DbEnv handle open and not
  242. // doing a close is generally considered an error.
  243. //
  244. // We used to allow DbEnv objects to be closed and reopened.
  245. // This implied always keeping a valid DB_ENV object, and
  246. // coordinating the open objects between Db/DbEnv turned
  247. // out to be overly complicated. Now we do not allow this.
  248. DbEnv::DbEnv(u_int32_t flags)
  249. : imp_(0)
  250. , construct_error_(0)
  251. , construct_flags_(flags)
  252. , error_stream_(0)
  253. , message_stream_(0)
  254. , app_dispatch_callback_(0)
  255. , feedback_callback_(0)
  256. , paniccall_callback_(0)
  257. , event_func_callback_(0)
  258. , rep_send_callback_(0)
  259. {
  260. if ((construct_error_ = initialize(0)) != 0)
  261. DB_ERROR(this, "DbEnv::DbEnv", construct_error_,
  262. error_policy());
  263. }
  264. DbEnv::DbEnv(DB_ENV *dbenv, u_int32_t flags)
  265. : imp_(0)
  266. , construct_error_(0)
  267. , construct_flags_(flags)
  268. , error_stream_(0)
  269. , message_stream_(0)
  270. , app_dispatch_callback_(0)
  271. , feedback_callback_(0)
  272. , paniccall_callback_(0)
  273. , event_func_callback_(0)
  274. , rep_send_callback_(0)
  275. {
  276. if ((construct_error_ = initialize(dbenv)) != 0)
  277. DB_ERROR(this, "DbEnv::DbEnv", construct_error_,
  278. error_policy());
  279. }
  280. // If the DB_ENV handle is still open, we close it. This is to make stack
  281. // allocation of DbEnv objects easier so that they are cleaned up in the error
  282. // path. Note that the C layer catches cases where handles are open in the
  283. // environment at close time and reports an error. Applications should call
  284. // close explicitly in normal (non-exceptional) cases to check the return
  285. // value.
  286. //
  287. DbEnv::~DbEnv()
  288. {
  289. DB_ENV *dbenv = unwrap(this);
  290. if (dbenv != NULL) {
  291. (void)dbenv->close(dbenv, 0);
  292. cleanup();
  293. }
  294. }
  295. // called by destructors before the DB_ENV is destroyed.
  296. void DbEnv::cleanup()
  297. {
  298. imp_ = 0;
  299. }
  300. int DbEnv::close(u_int32_t flags)
  301. {
  302. int ret;
  303. DB_ENV *dbenv = unwrap(this);
  304. ret = dbenv->close(dbenv, flags);
  305. // after a close (no matter if success or failure),
  306. // the underlying DB_ENV object must not be accessed.
  307. cleanup();
  308. // It's safe to throw an error after the close,
  309. // since our error mechanism does not peer into
  310. // the DB* structures.
  311. //
  312. if (ret != 0)
  313. DB_ERROR(this, "DbEnv::close", ret, error_policy());
  314. return (ret);
  315. }
  316. DBENV_METHOD(dbremove,
  317. (DbTxn *txn, const char *name, const char *subdb, u_int32_t flags),
  318. (dbenv, unwrap(txn), name, subdb, flags))
  319. DBENV_METHOD(dbrename, (DbTxn *txn, const char *name, const char *subdb,
  320. const char *newname, u_int32_t flags),
  321. (dbenv, unwrap(txn), name, subdb, newname, flags))
  322. void DbEnv::err(int error, const char *format, ...)
  323. {
  324. DB_ENV *dbenv = unwrap(this);
  325. DB_REAL_ERR(dbenv, error, DB_ERROR_SET, 1, format);
  326. }
  327. // Return a tristate value corresponding to whether we should
  328. // throw exceptions on errors:
  329. // ON_ERROR_RETURN
  330. // ON_ERROR_THROW
  331. // ON_ERROR_UNKNOWN
  332. //
  333. int DbEnv::error_policy()
  334. {
  335. if ((construct_flags_ & DB_CXX_NO_EXCEPTIONS) != 0) {
  336. return (ON_ERROR_RETURN);
  337. }
  338. else {
  339. return (ON_ERROR_THROW);
  340. }
  341. }
  342. void DbEnv::errx(const char *format, ...)
  343. {
  344. DB_ENV *dbenv = unwrap(this);
  345. DB_REAL_ERR(dbenv, 0, DB_ERROR_NOT_SET, 1, format);
  346. }
  347. void *DbEnv::get_app_private() const
  348. {
  349. return unwrapConst(this)->app_private;
  350. }
  351. DBENV_METHOD(failchk, (u_int32_t flags), (dbenv, flags))
  352. DBENV_METHOD(fileid_reset, (const char *file, u_int32_t flags),
  353. (dbenv, file, flags))
  354. DBENV_METHOD(get_home, (const char **homep), (dbenv, homep))
  355. DBENV_METHOD(get_open_flags, (u_int32_t *flagsp), (dbenv, flagsp))
  356. DBENV_METHOD(get_data_dirs, (const char ***dirspp), (dbenv, dirspp))
  357. bool DbEnv::is_bigendian()
  358. {
  359. return unwrap(this)->is_bigendian() ? true : false;
  360. }
  361. DBENV_METHOD(get_thread_count, (u_int32_t *count), (dbenv, count))
  362. DBENV_METHOD(set_thread_count, (u_int32_t count), (dbenv, count))
  363. // used internally during constructor
  364. // to associate an existing DB_ENV with this DbEnv,
  365. // or create a new one.
  366. //
  367. int DbEnv::initialize(DB_ENV *dbenv)
  368. {
  369. int ret;
  370. last_known_error_policy = error_policy();
  371. if (dbenv == 0) {
  372. // Create a new DB_ENV environment.
  373. if ((ret = ::db_env_create(&dbenv,
  374. construct_flags_ & ~DB_CXX_NO_EXCEPTIONS)) != 0)
  375. return (ret);
  376. }
  377. imp_ = dbenv;
  378. dbenv->api1_internal = this; // for DB_ENV* to DbEnv* conversion
  379. return (0);
  380. }
  381. // lock methods
  382. DBENV_METHOD(lock_detect, (u_int32_t flags, u_int32_t atype, int *aborted),
  383. (dbenv, flags, atype, aborted))
  384. DBENV_METHOD_ERR(lock_get,
  385. (u_int32_t locker, u_int32_t flags, Dbt *obj,
  386. db_lockmode_t lock_mode, DbLock *lock),
  387. (dbenv, locker, flags, obj, lock_mode, &lock->lock_),
  388. DbEnv::runtime_error_lock_get(this, "DbEnv::lock_get", ret,
  389. DB_LOCK_GET, lock_mode, obj, *lock,
  390. -1, error_policy()))
  391. DBENV_METHOD(lock_id, (u_int32_t *idp), (dbenv, idp))
  392. DBENV_METHOD(lock_id_free, (u_int32_t id), (dbenv, id))
  393. DBENV_METHOD(lock_put, (DbLock *lock), (dbenv, &lock->lock_))
  394. DBENV_METHOD(lock_stat, (DB_LOCK_STAT **statp, u_int32_t flags),
  395. (dbenv, statp, flags))
  396. DBENV_METHOD(lock_stat_print, (u_int32_t flags), (dbenv, flags))
  397. DBENV_METHOD_ERR(lock_vec,
  398. (u_int32_t locker, u_int32_t flags, DB_LOCKREQ list[],
  399. int nlist, DB_LOCKREQ **elist_returned),
  400. (dbenv, locker, flags, list, nlist, elist_returned),
  401. DbEnv::runtime_error_lock_get(this, "DbEnv::lock_vec", ret,
  402. (*elist_returned)->op, (*elist_returned)->mode,
  403. Dbt::get_Dbt((*elist_returned)->obj), DbLock((*elist_returned)->lock),
  404. (int)((*elist_returned) - list), error_policy()))
  405. // log methods
  406. DBENV_METHOD(log_archive, (char **list[], u_int32_t flags),
  407. (dbenv, list, flags))
  408. int DbEnv::log_compare(const DbLsn *lsn0, const DbLsn *lsn1)
  409. {
  410. return (::log_compare(lsn0, lsn1));
  411. }
  412. // The following cast implies that DbLogc can be no larger than DB_LOGC
  413. DBENV_METHOD(log_cursor, (DbLogc **cursorp, u_int32_t flags),
  414. (dbenv, (DB_LOGC **)cursorp, flags))
  415. DBENV_METHOD(log_file, (DbLsn *lsn, char *namep, size_t len),
  416. (dbenv, lsn, namep, len))
  417. DBENV_METHOD(log_flush, (const DbLsn *lsn), (dbenv, lsn))
  418. DBENV_METHOD(log_get_config, (u_int32_t which, int *onoffp),
  419. (dbenv, which, onoffp))
  420. DBENV_METHOD(log_put, (DbLsn *lsn, const Dbt *data, u_int32_t flags),
  421. (dbenv, lsn, data, flags))
  422. int DbEnv::log_printf(DbTxn *txn, const char *fmt, ...)
  423. {
  424. DB_ENV *dbenv = unwrap(this);
  425. va_list ap;
  426. int ret;
  427. va_start(ap, fmt);
  428. ret = __log_printf_pp(dbenv, unwrap(txn), fmt, ap);
  429. va_end(ap);
  430. return (ret);
  431. }
  432. DBENV_METHOD(log_set_config, (u_int32_t which, int onoff),
  433. (dbenv, which, onoff))
  434. DBENV_METHOD(log_stat, (DB_LOG_STAT **spp, u_int32_t flags),
  435. (dbenv, spp, flags))
  436. DBENV_METHOD(log_stat_print, (u_int32_t flags), (dbenv, flags))
  437. DBENV_METHOD(lsn_reset, (const char *file, u_int32_t flags),
  438. (dbenv, file, flags))
  439. int DbEnv::memp_fcreate(DbMpoolFile **dbmfp, u_int32_t flags)
  440. {
  441. DB_ENV *dbenv = unwrap(this);
  442. int ret;
  443. DB_MPOOLFILE *mpf;
  444. if (dbenv == NULL)
  445. ret = EINVAL;
  446. else
  447. ret = dbenv->memp_fcreate(dbenv, &mpf, flags);
  448. if (DB_RETOK_STD(ret)) {
  449. *dbmfp = new DbMpoolFile();
  450. (*dbmfp)->imp_ = mpf;
  451. } else
  452. DB_ERROR(this, "DbMpoolFile::f_create", ret, ON_ERROR_UNKNOWN);
  453. return (ret);
  454. }
  455. DBENV_METHOD(memp_register,
  456. (int ftype, pgin_fcn_type pgin_fcn, pgout_fcn_type pgout_fcn),
  457. (dbenv, ftype, pgin_fcn, pgout_fcn))
  458. // memory pool methods
  459. DBENV_METHOD(memp_stat,
  460. (DB_MPOOL_STAT **gsp, DB_MPOOL_FSTAT ***fsp, u_int32_t flags),
  461. (dbenv, gsp, fsp, flags))
  462. DBENV_METHOD(memp_stat_print, (u_int32_t flags), (dbenv, flags))
  463. DBENV_METHOD(memp_sync, (DbLsn *sn), (dbenv, sn))
  464. DBENV_METHOD(memp_trickle, (int pct, int *nwrotep), (dbenv, pct, nwrotep))
  465. // If an error occurred during the constructor, report it now.
  466. // Otherwise, call the underlying DB->open method.
  467. //
  468. int DbEnv::open(const char *db_home, u_int32_t flags, int mode)
  469. {
  470. int ret;
  471. DB_ENV *dbenv = unwrap(this);
  472. if (construct_error_ != 0)
  473. ret = construct_error_;
  474. else
  475. ret = dbenv->open(dbenv, db_home, flags, mode);
  476. if (!DB_RETOK_STD(ret))
  477. DB_ERROR(this, "DbEnv::open", ret, error_policy());
  478. return (ret);
  479. }
  480. int DbEnv::remove(const char *db_home, u_int32_t flags)
  481. {
  482. int ret;
  483. DB_ENV *dbenv = unwrap(this);
  484. ret = dbenv->remove(dbenv, db_home, flags);
  485. // after a remove (no matter if success or failure),
  486. // the underlying DB_ENV object must not be accessed,
  487. // so we clean up in advance.
  488. //
  489. cleanup();
  490. if (ret != 0)
  491. DB_ERROR(this, "DbEnv::remove", ret, error_policy());
  492. return (ret);
  493. }
  494. // Report an error associated with the DbEnv.
  495. // error_policy is one of:
  496. // ON_ERROR_THROW throw an error
  497. // ON_ERROR_RETURN do nothing here, the caller will return an error
  498. // ON_ERROR_UNKNOWN defer the policy to policy saved in DbEnv::DbEnv
  499. //
  500. void DbEnv::runtime_error(DbEnv *dbenv,
  501. const char *caller, int error, int error_policy)
  502. {
  503. if (error_policy == ON_ERROR_UNKNOWN)
  504. error_policy = last_known_error_policy;
  505. if (error_policy == ON_ERROR_THROW) {
  506. // Creating and throwing the object in two separate
  507. // statements seems to be necessary for HP compilers.
  508. switch (error) {
  509. case DB_LOCK_DEADLOCK:
  510. {
  511. DbDeadlockException dl_except(caller);
  512. dl_except.set_env(dbenv);
  513. throw dl_except;
  514. }
  515. case DB_LOCK_NOTGRANTED:
  516. {
  517. DbLockNotGrantedException lng_except(caller);
  518. lng_except.set_env(dbenv);
  519. throw lng_except;
  520. }
  521. case DB_REP_HANDLE_DEAD:
  522. {
  523. DbRepHandleDeadException hd_except(caller);
  524. hd_except.set_env(dbenv);
  525. throw hd_except;
  526. }
  527. case DB_RUNRECOVERY:
  528. {
  529. DbRunRecoveryException rr_except(caller);
  530. rr_except.set_env(dbenv);
  531. throw rr_except;
  532. }
  533. default:
  534. {
  535. DbException except(caller, error);
  536. except.set_env(dbenv);
  537. throw except;
  538. }
  539. }
  540. }
  541. }
  542. // Like DbEnv::runtime_error, but issue a DbMemoryException
  543. // based on the fact that this Dbt is not large enough.
  544. void DbEnv::runtime_error_dbt(DbEnv *dbenv,
  545. const char *caller, Dbt *dbt, int error_policy)
  546. {
  547. if (error_policy == ON_ERROR_UNKNOWN)
  548. error_policy = last_known_error_policy;
  549. if (error_policy == ON_ERROR_THROW) {
  550. // Creating and throwing the object in two separate
  551. // statements seems to be necessary for HP compilers.
  552. DbMemoryException except(caller, dbt);
  553. except.set_env(dbenv);
  554. throw except;
  555. }
  556. }
  557. // Like DbEnv::runtime_error, but issue a DbLockNotGrantedException,
  558. // or a regular runtime error.
  559. // call regular runtime_error if it
  560. void DbEnv::runtime_error_lock_get(DbEnv *dbenv,
  561. const char *caller, int error,
  562. db_lockop_t op, db_lockmode_t mode, Dbt *obj,
  563. DbLock lock, int index, int error_policy)
  564. {
  565. if (error != DB_LOCK_NOTGRANTED) {
  566. runtime_error(dbenv, caller, error, error_policy);
  567. return;
  568. }
  569. if (error_policy == ON_ERROR_UNKNOWN)
  570. error_policy = last_known_error_policy;
  571. if (error_policy == ON_ERROR_THROW) {
  572. // Creating and throwing the object in two separate
  573. // statements seems to be necessary for HP compilers.
  574. DbLockNotGrantedException except(caller, op, mode,
  575. obj, lock, index);
  576. except.set_env(dbenv);
  577. throw except;
  578. }
  579. }
  580. void DbEnv::_stream_error_function(
  581. const DB_ENV *dbenv, const char *prefix, const char *message)
  582. {
  583. const DbEnv *cxxenv = DbEnv::get_const_DbEnv(dbenv);
  584. if (cxxenv == 0) {
  585. DB_ERROR(0,
  586. "DbEnv::stream_error", EINVAL, ON_ERROR_UNKNOWN);
  587. return;
  588. }
  589. if (cxxenv->error_callback_)
  590. cxxenv->error_callback_(cxxenv, prefix, message);
  591. else if (cxxenv->error_stream_) {
  592. // HP compilers need the extra casts, we don't know why.
  593. if (prefix) {
  594. (*cxxenv->error_stream_) << prefix;
  595. (*cxxenv->error_stream_) << (const char *)": ";
  596. }
  597. if (message)
  598. (*cxxenv->error_stream_) << (const char *)message;
  599. (*cxxenv->error_stream_) << (const char *)"\n";
  600. }
  601. }
  602. void DbEnv::_stream_message_function(const DB_ENV *dbenv, const char *message)
  603. {
  604. const DbEnv *cxxenv = DbEnv::get_const_DbEnv(dbenv);
  605. if (cxxenv == 0) {
  606. DB_ERROR(0,
  607. "DbEnv::stream_message", EINVAL, ON_ERROR_UNKNOWN);
  608. return;
  609. }
  610. if (cxxenv->message_callback_)
  611. cxxenv->message_callback_(cxxenv, message);
  612. else if (cxxenv->message_stream_) {
  613. // HP compilers need the extra casts, we don't know why.
  614. (*cxxenv->message_stream_) << (const char *)message;
  615. (*cxxenv->message_stream_) << (const char *)"\n";
  616. }
  617. }
  618. // static method
  619. char *DbEnv::strerror(int error)
  620. {
  621. return (db_strerror(error));
  622. }
  623. // We keep these alphabetical by field name,
  624. // for comparison with Java's list.
  625. //
  626. DBENV_METHOD(set_data_dir, (const char *dir), (dbenv, dir))
  627. DBENV_METHOD(get_encrypt_flags, (u_int32_t *flagsp),
  628. (dbenv, flagsp))
  629. DBENV_METHOD(set_encrypt, (const char *passwd, u_int32_t flags),
  630. (dbenv, passwd, flags))
  631. DBENV_METHOD_VOID(get_errfile, (FILE **errfilep), (dbenv, errfilep))
  632. DBENV_METHOD_VOID(set_errfile, (FILE *errfile), (dbenv, errfile))
  633. DBENV_METHOD_VOID(get_errpfx, (const char **errpfxp), (dbenv, errpfxp))
  634. DBENV_METHOD_VOID(set_errpfx, (const char *errpfx), (dbenv, errpfx))
  635. DBENV_METHOD(get_intermediate_dir_mode, (const char **modep), (dbenv, modep))
  636. DBENV_METHOD(set_intermediate_dir_mode, (const char *mode), (dbenv, mode))
  637. DBENV_METHOD(get_lg_bsize, (u_int32_t *bsizep), (dbenv, bsizep))
  638. DBENV_METHOD(set_lg_bsize, (u_int32_t bsize), (dbenv, bsize))
  639. DBENV_METHOD(get_lg_dir, (const char **dirp), (dbenv, dirp))
  640. DBENV_METHOD(set_lg_dir, (const char *dir), (dbenv, dir))
  641. DBENV_METHOD(get_lg_filemode, (int *modep), (dbenv, modep))
  642. DBENV_METHOD(set_lg_filemode, (int mode), (dbenv, mode))
  643. DBENV_METHOD(get_lg_max, (u_int32_t *maxp), (dbenv, maxp))
  644. DBENV_METHOD(set_lg_max, (u_int32_t max), (dbenv, max))
  645. DBENV_METHOD(get_lg_regionmax, (u_int32_t *regionmaxp), (dbenv, regionmaxp))
  646. DBENV_METHOD(set_lg_regionmax, (u_int32_t regionmax), (dbenv, regionmax))
  647. DBENV_METHOD(get_lk_conflicts, (const u_int8_t **lk_conflictsp, int *lk_maxp),
  648. (dbenv, lk_conflictsp, lk_maxp))
  649. DBENV_METHOD(set_lk_conflicts, (u_int8_t *lk_conflicts, int lk_max),
  650. (dbenv, lk_conflicts, lk_max))
  651. DBENV_METHOD(get_lk_detect, (u_int32_t *detectp), (dbenv, detectp))
  652. DBENV_METHOD(set_lk_detect, (u_int32_t detect), (dbenv, detect))
  653. DBENV_METHOD(get_lk_max_lockers, (u_int32_t *max_lockersp),
  654. (dbenv, max_lockersp))
  655. DBENV_METHOD(set_lk_max_lockers, (u_int32_t max_lockers), (dbenv, max_lockers))
  656. DBENV_METHOD(get_lk_max_locks, (u_int32_t *max_locksp), (dbenv, max_locksp))
  657. DBENV_METHOD(set_lk_max_locks, (u_int32_t max_locks), (dbenv, max_locks))
  658. DBENV_METHOD(get_lk_max_objects, (u_int32_t *max_objectsp),
  659. (dbenv, max_objectsp))
  660. DBENV_METHOD(set_lk_max_objects, (u_int32_t max_objects), (dbenv, max_objects))
  661. DBENV_METHOD(get_lk_partitions, (u_int32_t *partitionsp), (dbenv, partitionsp))
  662. DBENV_METHOD(set_lk_partitions, (u_int32_t partitions), (dbenv, partitions))
  663. DBENV_METHOD(get_mp_max_openfd, (int *maxopenfdp), (dbenv, maxopenfdp))
  664. DBENV_METHOD(set_mp_max_openfd, (int maxopenfd), (dbenv, maxopenfd))
  665. DBENV_METHOD(get_mp_max_write, (int *maxwritep, db_timeout_t *maxwrite_sleepp),
  666. (dbenv, maxwritep, maxwrite_sleepp))
  667. DBENV_METHOD(set_mp_max_write, (int maxwrite, db_timeout_t maxwrite_sleep),
  668. (dbenv, maxwrite, maxwrite_sleep))
  669. DBENV_METHOD(get_mp_mmapsize, (size_t *mmapsizep), (dbenv, mmapsizep))
  670. DBENV_METHOD(set_mp_mmapsize, (size_t mmapsize), (dbenv, mmapsize))
  671. DBENV_METHOD(get_mp_pagesize, (u_int32_t *pagesizep), (dbenv, pagesizep))
  672. DBENV_METHOD(set_mp_pagesize, (u_int32_t pagesize), (dbenv, pagesize))
  673. DBENV_METHOD(get_mp_tablesize, (u_int32_t *tablesizep), (dbenv, tablesizep))
  674. DBENV_METHOD(set_mp_tablesize, (u_int32_t tablesize), (dbenv, tablesize))
  675. DBENV_METHOD_VOID(get_msgfile, (FILE **msgfilep), (dbenv, msgfilep))
  676. DBENV_METHOD_VOID(set_msgfile, (FILE *msgfile), (dbenv, msgfile))
  677. DBENV_METHOD(get_tmp_dir, (const char **tmp_dirp), (dbenv, tmp_dirp))
  678. DBENV_METHOD(set_tmp_dir, (const char *tmp_dir), (dbenv, tmp_dir))
  679. DBENV_METHOD(get_tx_max, (u_int32_t *tx_maxp), (dbenv, tx_maxp))
  680. DBENV_METHOD(set_tx_max, (u_int32_t tx_max), (dbenv, tx_max))
  681. DBENV_METHOD(stat_print, (u_int32_t flags), (dbenv, flags))
  682. DBENV_METHOD_QUIET(get_alloc,
  683. (db_malloc_fcn_type *malloc_fcnp, db_realloc_fcn_type *realloc_fcnp,
  684. db_free_fcn_type *free_fcnp),
  685. (dbenv, malloc_fcnp, realloc_fcnp, free_fcnp))
  686. DBENV_METHOD_QUIET(set_alloc,
  687. (db_malloc_fcn_type malloc_fcn, db_realloc_fcn_type realloc_fcn,
  688. db_free_fcn_type free_fcn),
  689. (dbenv, malloc_fcn, realloc_fcn, free_fcn))
  690. void DbEnv::set_app_private(void *value)
  691. {
  692. unwrap(this)->app_private = value;
  693. }
  694. DBENV_METHOD(get_cachesize,
  695. (u_int32_t *gbytesp, u_int32_t *bytesp, int *ncachep),
  696. (dbenv, gbytesp, bytesp, ncachep))
  697. DBENV_METHOD(set_cachesize,
  698. (u_int32_t gbytes, u_int32_t bytes, int ncache),
  699. (dbenv, gbytes, bytes, ncache))
  700. DBENV_METHOD(get_cache_max, (u_int32_t *gbytesp, u_int32_t *bytesp),
  701. (dbenv, gbytesp, bytesp))
  702. DBENV_METHOD(set_cache_max, (u_int32_t gbytes, u_int32_t bytes),
  703. (dbenv, gbytes, bytes))
  704. DBENV_METHOD(get_create_dir, (const char **dirp), (dbenv, dirp))
  705. DBENV_METHOD(set_create_dir, (const char *dir), (dbenv, dir))
  706. void DbEnv::get_errcall(void (**argp)(const DbEnv *, const char *, const char *))
  707. {
  708. if (argp != NULL)
  709. *argp = error_callback_;
  710. return;
  711. }
  712. void DbEnv::set_errcall(void (*arg)(const DbEnv *, const char *, const char *))
  713. {
  714. DB_ENV *dbenv = unwrap(this);
  715. error_callback_ = arg;
  716. error_stream_ = 0;
  717. dbenv->set_errcall(dbenv, (arg == 0) ? 0 :
  718. _stream_error_function_c);
  719. }
  720. __DB_STD(ostream) *DbEnv::get_error_stream()
  721. {
  722. return (error_stream_);
  723. }
  724. void DbEnv::set_error_stream(__DB_STD(ostream) *stream)
  725. {
  726. DB_ENV *dbenv = unwrap(this);
  727. error_stream_ = stream;
  728. error_callback_ = 0;
  729. dbenv->set_errcall(dbenv, (stream == 0) ? 0 :
  730. _stream_error_function_c);
  731. }
  732. int DbEnv::get_feedback(void (**argp)(DbEnv *, int, int))
  733. {
  734. if (argp != NULL)
  735. *argp = feedback_callback_;
  736. return 0;
  737. }
  738. int DbEnv::set_feedback(void (*arg)(DbEnv *, int, int))
  739. {
  740. DB_ENV *dbenv = unwrap(this);
  741. feedback_callback_ = arg;
  742. return (dbenv->set_feedback(dbenv,
  743. arg == 0 ? 0 : _feedback_intercept_c));
  744. }
  745. DBENV_METHOD(get_flags, (u_int32_t *flagsp), (dbenv, flagsp))
  746. DBENV_METHOD(set_flags, (u_int32_t flags, int onoff), (dbenv, flags, onoff))
  747. void DbEnv::get_msgcall(void (**argp)(const DbEnv *, const char *))
  748. {
  749. if (argp != NULL)
  750. *argp = message_callback_;
  751. }
  752. void DbEnv::set_msgcall(void (*arg)(const DbEnv *, const char *))
  753. {
  754. DB_ENV *dbenv = unwrap(this);
  755. message_callback_ = arg;
  756. message_stream_ = 0;
  757. dbenv->set_msgcall(dbenv, (arg == 0) ? 0 :
  758. _stream_message_function_c);
  759. }
  760. __DB_STD(ostream) *DbEnv::get_message_stream()
  761. {
  762. return (message_stream_);
  763. }
  764. void DbEnv::set_message_stream(__DB_STD(ostream) *stream)
  765. {
  766. DB_ENV *dbenv = unwrap(this);
  767. message_stream_ = stream;
  768. message_callback_ = 0;
  769. dbenv->set_msgcall(dbenv, (stream == 0) ? 0 :
  770. _stream_message_function_c);
  771. }
  772. int DbEnv::set_paniccall(void (*arg)(DbEnv *, int))
  773. {
  774. DB_ENV *dbenv = unwrap(this);
  775. paniccall_callback_ = arg;
  776. return (dbenv->set_paniccall(dbenv,
  777. arg == 0 ? 0 : _paniccall_intercept_c));
  778. }
  779. int DbEnv::set_event_notify(void (*arg)(DbEnv *, u_int32_t, void *))
  780. {
  781. DB_ENV *dbenv = unwrap(this);
  782. event_func_callback_ = arg;
  783. return (dbenv->set_event_notify(dbenv,
  784. arg == 0 ? 0 : _event_func_intercept_c));
  785. }
  786. DBENV_METHOD(set_rpc_server,
  787. (void *cl, char *host, long tsec, long ssec, u_int32_t flags),
  788. (dbenv, cl, host, tsec, ssec, flags))
  789. DBENV_METHOD(get_shm_key, (long *shm_keyp), (dbenv, shm_keyp))
  790. DBENV_METHOD(set_shm_key, (long shm_key), (dbenv, shm_key))
  791. int DbEnv::get_app_dispatch
  792. (int (**argp)(DbEnv *, Dbt *, DbLsn *, db_recops))
  793. {
  794. if (argp != NULL)
  795. *argp = app_dispatch_callback_;
  796. return 0;
  797. }
  798. int DbEnv::set_app_dispatch
  799. (int (*arg)(DbEnv *, Dbt *, DbLsn *, db_recops))
  800. {
  801. DB_ENV *dbenv = unwrap(this);
  802. int ret;
  803. app_dispatch_callback_ = arg;
  804. if ((ret = dbenv->set_app_dispatch(dbenv,
  805. arg == 0 ? 0 : _app_dispatch_intercept_c)) != 0)
  806. DB_ERROR(this, "DbEnv::set_app_dispatch", ret, error_policy());
  807. return (ret);
  808. }
  809. int DbEnv::get_isalive
  810. (int (**argp)(DbEnv *, pid_t, db_threadid_t, u_int32_t))
  811. {
  812. if (argp != NULL)
  813. *argp = isalive_callback_;
  814. return 0;
  815. }
  816. int DbEnv::set_isalive
  817. (int (*arg)(DbEnv *, pid_t, db_threadid_t, u_int32_t))
  818. {
  819. DB_ENV *dbenv = unwrap(this);
  820. int ret;
  821. isalive_callback_ = arg;
  822. if ((ret = dbenv->set_isalive(dbenv,
  823. arg == 0 ? 0 : _isalive_intercept_c)) != 0)
  824. DB_ERROR(this, "DbEnv::set_isalive", ret, error_policy());
  825. return (ret);
  826. }
  827. DBENV_METHOD(get_tx_timestamp, (time_t *timestamp), (dbenv, timestamp))
  828. DBENV_METHOD(set_tx_timestamp, (time_t *timestamp), (dbenv, timestamp))
  829. DBENV_METHOD(get_verbose, (u_int32_t which, int *onoffp),
  830. (dbenv, which, onoffp))
  831. DBENV_METHOD(set_verbose, (u_int32_t which, int onoff), (dbenv, which, onoff))
  832. DBENV_METHOD(mutex_alloc,
  833. (u_int32_t flags, db_mutex_t *mutexp), (dbenv, flags, mutexp))
  834. DBENV_METHOD(mutex_free, (db_mutex_t mutex), (dbenv, mutex))
  835. DBENV_METHOD(mutex_get_align, (u_int32_t *argp), (dbenv, argp))
  836. DBENV_METHOD(mutex_get_increment, (u_int32_t *argp), (dbenv, argp))
  837. DBENV_METHOD(mutex_get_max, (u_int32_t *argp), (dbenv, argp))
  838. DBENV_METHOD(mutex_get_tas_spins, (u_int32_t *argp), (dbenv, argp))
  839. DBENV_METHOD(mutex_lock, (db_mutex_t mutex), (dbenv, mutex))
  840. DBENV_METHOD(mutex_set_align, (u_int32_t arg), (dbenv, arg))
  841. DBENV_METHOD(mutex_set_increment, (u_int32_t arg), (dbenv, arg))
  842. DBENV_METHOD(mutex_set_max, (u_int32_t arg), (dbenv, arg))
  843. DBENV_METHOD(mutex_set_tas_spins, (u_int32_t arg), (dbenv, arg))
  844. DBENV_METHOD(mutex_stat,
  845. (DB_MUTEX_STAT **statp, u_int32_t flags), (dbenv, statp, flags))
  846. DBENV_METHOD(mutex_stat_print, (u_int32_t flags), (dbenv, flags))
  847. DBENV_METHOD(mutex_unlock, (db_mutex_t mutex), (dbenv, mutex))
  848. int DbEnv::get_thread_id_fn(void (**argp)(DbEnv *, pid_t *, db_threadid_t *))
  849. {
  850. if (argp != NULL)
  851. *argp = thread_id_callback_;
  852. return 0;
  853. }
  854. int DbEnv::set_thread_id(void (*arg)(DbEnv *, pid_t *, db_threadid_t *))
  855. {
  856. DB_ENV *dbenv = unwrap(this);
  857. int ret;
  858. thread_id_callback_ = arg;
  859. if ((ret = dbenv->set_thread_id(dbenv,
  860. arg == 0 ? 0 : _thread_id_intercept_c)) != 0)
  861. DB_ERROR(this, "DbEnv::set_thread_id", ret, error_policy());
  862. return (ret);
  863. }
  864. int DbEnv::get_thread_id_string_fn(
  865. char *(**argp)(DbEnv *, pid_t, db_threadid_t, char *))
  866. {
  867. if (argp != NULL)
  868. *argp = thread_id_string_callback_;
  869. return 0;
  870. }
  871. int DbEnv::set_thread_id_string(
  872. char *(*arg)(DbEnv *, pid_t, db_threadid_t, char *))
  873. {
  874. DB_ENV *dbenv = unwrap(this);
  875. int ret;
  876. thread_id_string_callback_ = arg;
  877. if ((ret = dbenv->set_thread_id_string(dbenv,
  878. arg == 0 ? 0 : _thread_id_string_intercept_c)) != 0)
  879. DB_ERROR(this, "DbEnv::set_thread_id_string", ret,
  880. error_policy());
  881. return (ret);
  882. }
  883. DBENV_METHOD(add_data_dir, (const char *dir), (dbenv, dir))
  884. int DbEnv::cdsgroup_begin(DbTxn **tid)
  885. {
  886. DB_ENV *dbenv = unwrap(this);
  887. DB_TXN *txn;
  888. int ret;
  889. ret = dbenv->cdsgroup_begin(dbenv, &txn);
  890. if (DB_RETOK_STD(ret))
  891. *tid = new DbTxn(txn, NULL);
  892. else
  893. DB_ERROR(this, "DbEnv::cdsgroup_begin", ret, error_policy());
  894. return (ret);
  895. }
  896. int DbEnv::txn_begin(DbTxn *pid, DbTxn **tid, u_int32_t flags)
  897. {
  898. DB_ENV *dbenv = unwrap(this);
  899. DB_TXN *txn;
  900. int ret;
  901. ret = dbenv->txn_begin(dbenv, unwrap(pid), &txn, flags);
  902. if (DB_RETOK_STD(ret))
  903. *tid = new DbTxn(txn, pid);
  904. else
  905. DB_ERROR(this, "DbEnv::txn_begin", ret, error_policy());
  906. return (ret);
  907. }
  908. DBENV_METHOD(txn_checkpoint, (u_int32_t kbyte, u_int32_t min, u_int32_t flags),
  909. (dbenv, kbyte, min, flags))
  910. int DbEnv::txn_recover(DbPreplist *preplist, u_int32_t count,
  911. u_int32_t *retp, u_int32_t flags)
  912. {
  913. DB_ENV *dbenv = unwrap(this);
  914. DB_PREPLIST *c_preplist;
  915. u_int32_t i;
  916. int ret;
  917. /*
  918. * We need to allocate some local storage for the
  919. * returned preplist, and that requires us to do
  920. * our own argument validation.
  921. */
  922. if (count <= 0)
  923. ret = EINVAL;
  924. else
  925. ret = __os_malloc(dbenv->env, sizeof(DB_PREPLIST) * count,
  926. &c_preplist);
  927. if (ret != 0) {
  928. DB_ERROR(this, "DbEnv::txn_recover", ret, error_policy());
  929. return (ret);
  930. }
  931. if ((ret =
  932. dbenv->txn_recover(dbenv, c_preplist, count, retp, flags)) != 0) {
  933. __os_free(dbenv->env, c_preplist);
  934. DB_ERROR(this, "DbEnv::txn_recover", ret, error_policy());
  935. return (ret);
  936. }
  937. for (i = 0; i < *retp; i++) {
  938. preplist[i].txn = new DbTxn(NULL);
  939. preplist[i].txn->imp_ = c_preplist[i].txn;
  940. memcpy(preplist[i].gid, c_preplist[i].gid,
  941. sizeof(preplist[i].gid));
  942. }
  943. __os_free(dbenv->env, c_preplist);
  944. return (0);
  945. }
  946. DBENV_METHOD(txn_stat, (DB_TXN_STAT **statp, u_int32_t flags),
  947. (dbenv, statp, flags))
  948. DBENV_METHOD(txn_stat_print, (u_int32_t flags), (dbenv, flags))
  949. int DbEnv::rep_set_transport(int myid, int (*arg)(DbEnv *,
  950. const Dbt *, const Dbt *, const DbLsn *, int, u_int32_t))
  951. {
  952. DB_ENV *dbenv = unwrap(this);
  953. int ret;
  954. rep_send_callback_ = arg;
  955. if ((ret = dbenv->rep_set_transport(dbenv, myid,
  956. arg == 0 ? 0 : _rep_send_intercept_c)) != 0)
  957. DB_ERROR(this, "DbEnv::rep_set_transport", ret, error_policy());
  958. return (ret);
  959. }
  960. DBENV_METHOD(rep_elect, (u_int32_t nsites, u_int32_t nvotes, u_int32_t flags),
  961. (dbenv, nsites, nvotes, flags))
  962. DBENV_METHOD(rep_flush, (), (dbenv))
  963. DBENV_METHOD(rep_get_config, (u_int32_t which, int *onoffp),
  964. (dbenv, which, onoffp))
  965. DBENV_METHOD(rep_get_request, (u_int32_t *min, u_int32_t *max),
  966. (dbenv, min, max))
  967. DBENV_METHOD(rep_set_request, (u_int32_t min, u_int32_t max), (dbenv, min, max))
  968. int DbEnv::rep_process_message(Dbt *control,
  969. Dbt *rec, int id, DbLsn *ret_lsnp)
  970. {
  971. DB_ENV *dbenv = unwrap(this);
  972. int ret;
  973. ret = dbenv->rep_process_message(dbenv, control, rec, id, ret_lsnp);
  974. if (!DB_RETOK_REPPMSG(ret))
  975. DB_ERROR(this, "DbEnv::rep_process_message", ret,
  976. error_policy());
  977. return (ret);
  978. }
  979. DBENV_METHOD(rep_set_config,
  980. (u_int32_t which, int onoff), (dbenv, which, onoff))
  981. DBENV_METHOD(rep_start,
  982. (Dbt *cookie, u_int32_t flags),
  983. (dbenv, (DBT *)cookie, flags))
  984. DBENV_METHOD(rep_stat, (DB_REP_STAT **statp, u_int32_t flags),
  985. (dbenv, statp, flags))
  986. DBENV_METHOD(rep_stat_print, (u_int32_t flags), (dbenv, flags))
  987. DBENV_METHOD(rep_sync, (u_int32_t flags), (dbenv, flags))
  988. DBENV_METHOD(rep_get_clockskew, (u_int32_t *fast_clockp, u_int32_t *slow_clockp),
  989. (dbenv, fast_clockp, slow_clockp))
  990. DBENV_METHOD(rep_set_clockskew, (u_int32_t fast_clock, u_int32_t slow_clock),
  991. (dbenv, fast_clock, slow_clock))
  992. DBENV_METHOD(rep_get_limit, (u_int32_t *gbytesp, u_int32_t *bytesp),
  993. (dbenv, gbytesp, bytesp))
  994. DBENV_METHOD(rep_set_limit, (u_int32_t gbytes, u_int32_t bytes),
  995. (dbenv, gbytes, bytes))
  996. //
  997. // Begin advanced replication API method implementations
  998. DBENV_METHOD(rep_get_nsites, (u_int32_t *n), (dbenv, n))
  999. DBENV_METHOD(rep_set_nsites, (u_int32_t n), (dbenv, n))
  1000. DBENV_METHOD(rep_get_priority, (u_int32_t *priority),
  1001. (dbenv, priority))
  1002. DBENV_METHOD(rep_set_priority, (u_int32_t priority),
  1003. (dbenv, priority))
  1004. DBENV_METHOD(rep_get_timeout, (int which, db_timeout_t * timeout),
  1005. (dbenv, which, timeout))
  1006. DBENV_METHOD(rep_set_timeout, (int which, db_timeout_t timeout),
  1007. (dbenv, which, timeout))
  1008. DBENV_METHOD(repmgr_add_remote_site, (const char* host, u_int16_t port,
  1009. int * eidp, u_int32_t flags), (dbenv, host, port, eidp, flags))
  1010. DBENV_METHOD(repmgr_get_ack_policy, (int *policy), (dbenv, policy))
  1011. DBENV_METHOD(repmgr_set_ack_policy, (int policy), (dbenv, policy))
  1012. DBENV_METHOD(repmgr_set_local_site, (const char* host, u_int16_t port,
  1013. u_int32_t flags), (dbenv, host, port, flags))
  1014. DBENV_METHOD(repmgr_site_list, (u_int *countp, DB_REPMGR_SITE **listp),
  1015. (dbenv, countp, listp))
  1016. int DbEnv::repmgr_start(int nthreads, u_int32_t flags)
  1017. {
  1018. DB_ENV *dbenv = unwrap(this);
  1019. int ret;
  1020. ret = dbenv->repmgr_start(dbenv, nthreads, flags);
  1021. if (!DB_RETOK_REPMGR_START(ret))
  1022. DB_ERROR(this, "DbEnv::repmgr_start", ret,
  1023. error_policy());
  1024. return (ret);
  1025. }
  1026. DBENV_METHOD(repmgr_stat, (DB_REPMGR_STAT **statp, u_int32_t flags),
  1027. (dbenv, statp, flags))
  1028. DBENV_METHOD(repmgr_stat_print, (u_int32_t flags), (dbenv, flags))
  1029. // End advanced replication API method implementations.
  1030. DBENV_METHOD(get_timeout,
  1031. (db_timeout_t *timeoutp, u_int32_t flags),
  1032. (dbenv, timeoutp, flags))
  1033. DBENV_METHOD(set_timeout,
  1034. (db_timeout_t timeout, u_int32_t flags),
  1035. (dbenv, timeout, flags))
  1036. // static method
  1037. char *DbEnv::version(int *major, int *minor, int *patch)
  1038. {
  1039. return (db_version(major, minor, patch));
  1040. }
  1041. // static method
  1042. DbEnv *DbEnv::wrap_DB_ENV(DB_ENV *dbenv)
  1043. {
  1044. DbEnv *wrapped_env = get_DbEnv(dbenv);
  1045. return (wrapped_env != NULL) ? wrapped_env : new DbEnv(dbenv, 0);
  1046. }