/* * log_init -- * Initialize the logging subsystem. * * PUBLIC: int log_init __P((SCR *, EXF *)); */ int log_init(SCR *sp, EXF *ep) { DB_LOGC *logc; DBT data; size_t nlen; /* * !!! * ep MAY NOT BE THE SAME AS sp->ep, DON'T USE THE LATTER. * * Initialize the buffer. The logging subsystem has its own * buffers because the global ones are almost by definition * going to be in use when the log runs. */ sp->wp->l_lp = NULL; sp->wp->l_len = 0; ep->l_cursor.lno = 1; /* XXX Any valid recno. */ ep->l_cursor.cno = 0; ep->l_high = ep->l_cur = 1; if ((sp->db_error = ep->env->log_cursor(ep->env, &logc, 0)) != 0) { msgq(sp, M_DBERR, "env->log_cursor"); F_SET(ep, F_NOLOG); return (1); } nlen = 1024; retry: BINC_GOTO(sp, sp->wp->l_lp, sp->wp->l_len, nlen); memset(&data, 0, sizeof(data)); data.data = sp->wp->l_lp; data.ulen = sp->wp->l_len; data.flags = DB_DBT_USERMEM; switch ((sp->db_error = logc->get(logc, &ep->lsn_first, &data, DB_LAST))) { case ENOMEM: nlen = data.size; goto retry; default: alloc_err: msgq(sp, M_DBERR, "logc->get"); F_SET(ep, F_NOLOG); return (1); case 0: ; } MEMCPY(&ep->lsn_cur, &ep->lsn_first, 1); MEMCPY(&ep->lsn_high, &ep->lsn_first, 1); logc->close(logc, 0); ep->l_win = NULL; /*LOCK_INIT(sp->wp, ep);*/ return (0); }
// The name _flags prevents a name clash with __db_log_cursor::flags int DbLogc::close(u_int32_t _flags) { DB_LOGC *logc = this; int ret; ret = logc->close(logc, _flags); if (!DB_RETOK_STD(ret)) DB_ERROR("DbLogc::close", ret, ON_ERROR_UNKNOWN); return (ret); }
// The name _flags prevents a name clash with __db_log_cursor::flags int DbLogc::version(u_int32_t *versionp, u_int32_t _flags) { DB_LOGC *logc = this; int ret; ret = logc->version(logc, versionp, _flags); if (!DB_RETOK_LGGET(ret)) DB_ERROR(DbEnv::get_DbEnv(logc->env->dbenv), "DbLogc::version", ret, ON_ERROR_UNKNOWN); return (ret); }
// The name _flags prevents a name clash with __db_log_cursor::flags int DbLogc::close(u_int32_t _flags) { DB_LOGC *logc = this; int ret; DbEnv *dbenv2 = DbEnv::get_DbEnv(logc->env->dbenv); ret = logc->close(logc, _flags); if (!DB_RETOK_STD(ret)) DB_ERROR(dbenv2, "DbLogc::close", ret, ON_ERROR_UNKNOWN); return (ret); }
// The name _flags prevents a name clash with __db_log_cursor::flags int DbLogc::get(DbLsn *lsn, Dbt *data, u_int32_t _flags) { DB_LOGC *logc = this; int ret; ret = logc->get(logc, lsn, data, _flags); if (!DB_RETOK_LGGET(ret)) { if (ret == ENOMEM && DB_OVERFLOWED_DBT(data)) DB_ERROR_DBT("DbLogc::get", data, ON_ERROR_UNKNOWN); else DB_ERROR("DbLogc::get", ret, ON_ERROR_UNKNOWN); } return (ret); }
// The name _flags prevents a name clash with __db_log_cursor::flags int DbLogc::get(DbLsn *get_lsn, Dbt *data, u_int32_t _flags) { DB_LOGC *logc = this; int ret; ret = logc->get(logc, get_lsn, data, _flags); if (!DB_RETOK_LGGET(ret)) { if (ret == DB_BUFFER_SMALL) DB_ERROR_DBT(DbEnv::get_DbEnv(logc->env->dbenv), "DbLogc::get", data, ON_ERROR_UNKNOWN); else DB_ERROR(DbEnv::get_DbEnv(logc->env->dbenv), "DbLogc::get", ret, ON_ERROR_UNKNOWN); } return (ret); }
static VALUE bdb_lsn_log_get(int argc, VALUE *argv, VALUE obj) { struct dblsnst *lsnst; DBT data; VALUE res, a; int ret, flags; bdb_ENV *envst; #if HAVE_ST_DB_ENV_LOG_CURSOR DB_LOGC *cursor; #endif flags = DB_SET; if (rb_scan_args(argc, argv, "01", &a) == 1) { flags = NUM2INT(a); } GetLsn(obj, lsnst, envst); #if HAVE_ST_DB_ENV_LOG_CURSOR bdb_test_error(envst->envp->log_cursor(envst->envp, &cursor, 0)); #endif MEMZERO(&data, DBT, 1); data.flags |= DB_DBT_MALLOC; #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } ret = bdb_test_error(log_get(envst->envp->lg_info, lsnst->lsn, &data, flags)); #elif HAVE_ST_DB_ENV_LOG_CURSOR ret = cursor->get(cursor, lsnst->lsn, &data, flags); cursor->close(cursor, 0); ret = bdb_test_error(ret); #else ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flags)); #endif if (ret == DB_NOTFOUND) { return Qnil; } res = rb_tainted_str_new(data.data, data.size); free(data.data); return res; }