static VALUE bdb_log_register(VALUE obj, VALUE a) { #if ! (HAVE_ST_DB_ENV_LOG_REGISTER || HAVE_DB_LOG_REGISTER || HAVE_ST_DB_ENV_LG_INFO) rb_warn("log_register is obsolete"); return Qnil; #else bdb_DB *dbst; bdb_ENV *envst; if (TYPE(a) != T_STRING) { rb_raise(bdb_eFatal, "Need a filename"); } if (bdb_env_p(obj) == Qfalse) { rb_raise(bdb_eFatal, "Database must be open in an Env"); } Data_Get_Struct(obj, bdb_DB, dbst); Data_Get_Struct(dbst->env, bdb_ENV, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_register(envst->envp->lg_info, dbst->dbp, StringValuePtr(a), dbst->type, &envst->fidp)); #elif HAVE_ST_DB_ENV_LOG_REGISTER bdb_test_error(envst->envp->log_register(envst->envp, dbst->dbp, StringValuePtr(a))); #else #if HAVE_DB_LOG_REGISTER_4 bdb_test_error(log_register(envst->envp, dbst->dbp, StringValuePtr(a), &envst->fidp)); #else bdb_test_error(log_register(envst->envp, dbst->dbp, StringValuePtr(a))); #endif #endif return obj; #endif }
static VALUE bdb_log_unregister(VALUE obj) { #if ! (HAVE_ST_DB_ENV_LOG_UNREGISTER || HAVE_DB_LOG_UNREGISTER || HAVE_ST_DB_ENV_LG_INFO) rb_warn("log_unregister is obsolete"); return Qnil; #else bdb_DB *dbst; bdb_ENV *envst; if (bdb_env_p(obj) == Qfalse) { rb_raise(bdb_eFatal, "Database must be open in an Env"); } Data_Get_Struct(obj, bdb_DB, dbst); Data_Get_Struct(dbst->env, bdb_ENV, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_unregister(envst->envp->lg_info, envst->fidp)); #elif HAVE_ST_DB_ENV_LOG_UNREGISTER bdb_test_error(envst->envp->log_unregister(envst->envp, dbst->dbp)); #else #if HAVE_DB_LOG_REGISTER_4 bdb_test_error(log_unregister(envst->envp, envst->fidp)); #else bdb_test_error(log_unregister(envst->envp, dbst->dbp)); #endif #endif return obj; #endif }
static VALUE bdb_env_log_archive(int argc, VALUE *argv, VALUE obj) { char **list, **file; bdb_ENV *envst; int flag; VALUE res; GetEnvDB(obj, envst); flag = 0; list = NULL; if (rb_scan_args(argc, argv, "01", &res)) { flag = NUM2INT(res); } #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_archive(envst->envp->lg_info, &list, flag, NULL)); #elif HAVE_ST_DB_ENV_LOG_ARCHIVE bdb_test_error(envst->envp->log_archive(envst->envp, &list, flag)); #else #if HAVE_DB_LOG_ARCHIVE_4 bdb_test_error(log_archive(envst->envp, &list, flag, NULL)); #else bdb_test_error(log_archive(envst->envp, &list, flag)); #endif #endif res = rb_ary_new(); for (file = list; file != NULL && *file != NULL; file++) { rb_ary_push(res, rb_tainted_str_new2(*file)); } if (list != NULL) free(list); return res; }
static VALUE bdb_env_log_get(VALUE obj, VALUE a) { bdb_ENV *envst; DBT data; struct dblsnst *lsnst; VALUE res, lsn; int ret, flag; GetEnvDB(obj, envst); flag = NUM2INT(a); MEMZERO(&data, DBT, 1); data.flags |= DB_DBT_MALLOC; lsn = bdb_makelsn(obj); Data_Get_Struct(lsn, struct dblsnst, lsnst); #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, flag)); #else ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flag)); #endif if (ret == DB_NOTFOUND) { return Qnil; } res = rb_tainted_str_new(data.data, data.size); free(data.data); return rb_assoc_new(res, lsn); }
static VALUE bdb_s_log_put_internal(VALUE obj, VALUE a, int flag) { bdb_ENV *envst; VALUE ret; DBT data; struct dblsnst *lsnst; GetEnvDB(obj, envst); if (TYPE(a) != T_STRING) a = rb_str_to_str(a); ret = bdb_makelsn(obj); Data_Get_Struct(ret, struct dblsnst, lsnst); data.data = StringValuePtr(a); data.size = RSTRING_LEN(a); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_put(envst->envp->lg_info, lsnst->lsn, &data, flag)); #elif HAVE_ST_DB_ENV_LOG_PUT bdb_test_error(envst->envp->log_put(envst->envp, lsnst->lsn, &data, flag)); #else bdb_test_error(log_put(envst->envp, lsnst->lsn, &data, flag)); #endif return ret; }
static VALUE bdb_s_log_flush(int argc, VALUE *argv, VALUE obj) { bdb_ENV *envst; if (argc == 0) { GetEnvDB(obj, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_flush(envst->envp->lg_info, NULL)); #elif HAVE_ST_DB_ENV_LOG_FLUSH bdb_test_error(envst->envp->log_flush(envst->envp, NULL)); #else bdb_test_error(log_flush(envst->envp, NULL)); #endif return obj; } else if (argc == 1) { return bdb_s_log_put_internal(obj, argv[0], DB_FLUSH); } else { rb_raise(bdb_eFatal, "Invalid number of arguments"); } }
static VALUE bdb_lsn_log_flush(VALUE obj) { struct dblsnst *lsnst; bdb_ENV *envst; GetLsn(obj, lsnst, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_flush(envst->envp->lg_info, lsnst->lsn)); #elif HAVE_ST_DB_ENV_LOG_FLUSH bdb_test_error(envst->envp->log_flush(envst->envp, lsnst->lsn)); #else bdb_test_error(log_flush(envst->envp, lsnst->lsn)); #endif return obj; }
static VALUE bdb_lsn_log_file(VALUE obj) { struct dblsnst *lsnst; bdb_ENV *envst; char name[2048]; GetLsn(obj, lsnst, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } bdb_test_error(log_file(envst->envp->lg_info, lsnst->lsn, name, 2048)); #elif HAVE_ST_DB_ENV_LOG_FILE bdb_test_error(envst->envp->log_file(envst->envp, lsnst->lsn, name, 2048)); #else bdb_test_error(log_file(envst->envp, lsnst->lsn, name, 2048)); #endif return rb_tainted_str_new2(name); }
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; }
static VALUE bdb_env_i_get(VALUE obj) { bdb_ENV *envst; struct dblsnst *lsnst; log_cursor_close(obj); Data_Get_Struct(obj, struct dblsnst, lsnst); GetEnvDB(lsnst->env, envst); bdb_test_error(envst->envp->log_cursor(envst->envp, &lsnst->cursor, 0)); return bdb_i_each_log_get(obj, lsnst->flags); }
static VALUE log_cursor_close(VALUE obj) { struct dblsnst *lsnst; Data_Get_Struct(obj, struct dblsnst, lsnst); if (lsnst->cursor) { bdb_test_error(lsnst->cursor->close(lsnst->cursor, 0)); lsnst->cursor = 0; } return Qnil; }
static VALUE bdb_intern_shift_pop(VALUE obj, int depart, int len) { bdb_DB *dbst; DB_TXN *txnid; DBC *dbcp; DBT key, data; int i, ret, flags; db_recno_t recno; VALUE res; rb_secure(4); INIT_TXN(txnid, obj, dbst); #if HAVE_DB_CURSOR_4 bdb_test_error(dbst->dbp->cursor(dbst->dbp, txnid, &dbcp, 0)); #else bdb_test_error(dbst->dbp->cursor(dbst->dbp, txnid, &dbcp)); #endif SET_PARTIAL(dbst, data); flags = TEST_INIT_LOCK(dbst); res = rb_ary_new2(len); for (i = 0; i < len; i++) { MEMZERO(&key, DBT, 1); INIT_RECNO(dbst, key, recno); MEMZERO(&data, DBT, 1); data.flags = DB_DBT_MALLOC; bdb_cache_error(dbcp->c_get(dbcp, &key, &data, depart | flags), dbcp->c_close(dbcp), ret); if (ret == DB_NOTFOUND) break; rb_ary_push(res, bdb_test_load(obj, &data, FILTER_VALUE)); bdb_cache_error(dbcp->c_del(dbcp, 0), dbcp->c_close(dbcp), ret); if (dbst->len > 0) dbst->len--; } dbcp->c_close(dbcp); if (RARRAY_LEN(res) == 0) return Qnil; else if (RARRAY_LEN(res) == 1) return RARRAY_PTR(res)[0]; else return res; }
static VALUE bdb_log_cursor(VALUE lsn) { bdb_ENV *envst; struct dblsnst *lsnst; Data_Get_Struct(lsn, struct dblsnst, lsnst); if (!lsnst->cursor) { GetEnvDB(lsnst->env, envst); bdb_test_error(envst->envp->log_cursor(envst->envp, &lsnst->cursor, 0)); bdb_ary_push(&envst->db_ary, lsn); } return lsn; }
static VALUE bdb_i_each_log_get(VALUE obj, int flag) { #if ! HAVE_ST_DB_ENV_LOG_CURSOR bdb_ENV *envst; #endif struct dblsnst *lsnst, *lsnst1; DBT data; VALUE lsn, lsn1; VALUE res; int ret, init, flags; init = BDB_LOG_INIT; #if ! HAVE_ST_DB_ENV_LOG_CURSOR GetEnvDB(obj, envst); #else lsn = obj; Data_Get_Struct(obj, struct dblsnst, lsnst); flag = lsnst->flags; if (lsnst->cursor == 0) { DB_LSN *lsn1; init = BDB_LOG_SET; lsn1 = lsnst->lsn; lsn = bdb_makelsn(lsnst->env); Data_Get_Struct(lsn, struct dblsnst, lsnst); MEMCPY(lsnst->lsn, lsn1, DB_LSN, 1); bdb_log_cursor(lsn); } #endif do { #if ! HAVE_ST_DB_ENV_LOG_CURSOR lsn = bdb_makelsn(obj); Data_Get_Struct(lsn, struct dblsnst, lsnst); #endif MEMZERO(&data, DBT, 1); data.flags |= DB_DBT_MALLOC; switch (init) { case BDB_LOG_INIT: flags = (flag == DB_NEXT)?DB_FIRST:DB_LAST; break; case BDB_LOG_SET: flags = DB_SET; break; default: flags = flag; break; } init = BDB_LOG_NEXT; #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 = bdb_test_error(lsnst->cursor->get(lsnst->cursor, lsnst->lsn, &data, flags)); lsn1 = bdb_makelsn(lsnst->env); Data_Get_Struct(lsn1, struct dblsnst, lsnst1); MEMCPY(lsnst1->lsn, lsnst->lsn, DB_LSN, 1); #else ret = bdb_test_error(log_get(envst->envp, lsnst->lsn, &data, flags)); lsn1 = lsn; #endif if (ret == DB_NOTFOUND) { return Qnil; } res = rb_tainted_str_new(data.data, data.size); free(data.data); rb_yield(rb_assoc_new(res, lsn)); } while (1); return Qnil; }
static VALUE bdb_env_log_stat(int argc, VALUE *argv, VALUE obj) { DB_LOG_STAT *bdb_stat; bdb_ENV *envst; VALUE res, b; int flags; GetEnvDB(obj, envst); #if HAVE_ST_DB_ENV_LG_INFO if (!envst->envp->lg_info) { rb_raise(bdb_eFatal, "log region not open"); } if (argc != 0) { rb_raise(rb_eArgError, "invalid number of arguments (%d for 0)", argc); } bdb_test_error(log_stat(envst->envp->lg_info, &bdb_stat, 0)); #elif HAVE_ST_DB_ENV_LOG_STAT flags = 0; if (rb_scan_args(argc, argv, "01", &b) == 1) { flags = NUM2INT(b); } bdb_test_error(envst->envp->log_stat(envst->envp, &bdb_stat, flags)); #else if (argc != 0) { rb_raise(rb_eArgError, "invalid number of arguments (%d for 0)", argc); } #if HAVE_DB_LOG_STAT_3 bdb_test_error(log_stat(envst->envp, &bdb_stat, 0)); #else bdb_test_error(log_stat(envst->envp, &bdb_stat)); #endif #endif res = rb_hash_new(); rb_hash_aset(res, rb_tainted_str_new2("st_magic"), INT2NUM(bdb_stat->st_magic)); rb_hash_aset(res, rb_tainted_str_new2("st_version"), INT2NUM(bdb_stat->st_version)); rb_hash_aset(res, rb_tainted_str_new2("st_regsize"), INT2NUM(bdb_stat->st_regsize)); rb_hash_aset(res, rb_tainted_str_new2("st_mode"), INT2NUM(bdb_stat->st_mode)); #if HAVE_ST_DB_LOG_STAT_ST_REFCNT rb_hash_aset(res, rb_tainted_str_new2("st_refcnt"), INT2NUM(bdb_stat->st_refcnt)); #endif #if HAVE_ST_DB_LOG_STAT_ST_LG_BSIZE rb_hash_aset(res, rb_tainted_str_new2("st_lg_bsize"), INT2NUM(bdb_stat->st_lg_bsize)); #endif #if HAVE_ST_DB_LOG_STAT_ST_LG_SIZE rb_hash_aset(res, rb_tainted_str_new2("st_lg_size"), INT2NUM(bdb_stat->st_lg_size)); rb_hash_aset(res, rb_tainted_str_new2("st_lg_max"), INT2NUM(bdb_stat->st_lg_size)); #else rb_hash_aset(res, rb_tainted_str_new2("st_lg_max"), INT2NUM(bdb_stat->st_lg_max)); #endif rb_hash_aset(res, rb_tainted_str_new2("st_w_mbytes"), INT2NUM(bdb_stat->st_w_mbytes)); rb_hash_aset(res, rb_tainted_str_new2("st_w_bytes"), INT2NUM(bdb_stat->st_w_bytes)); rb_hash_aset(res, rb_tainted_str_new2("st_wc_mbytes"), INT2NUM(bdb_stat->st_wc_mbytes)); rb_hash_aset(res, rb_tainted_str_new2("st_wc_bytes"), INT2NUM(bdb_stat->st_wc_bytes)); rb_hash_aset(res, rb_tainted_str_new2("st_wcount"), INT2NUM(bdb_stat->st_wcount)); #if HAVE_ST_DB_LOG_STAT_ST_WCOUNT_FILL rb_hash_aset(res, rb_tainted_str_new2("st_wcount_fill"), INT2NUM(bdb_stat->st_wcount_fill)); #endif rb_hash_aset(res, rb_tainted_str_new2("st_scount"), INT2NUM(bdb_stat->st_scount)); rb_hash_aset(res, rb_tainted_str_new2("st_cur_file"), INT2NUM(bdb_stat->st_cur_file)); rb_hash_aset(res, rb_tainted_str_new2("st_cur_offset"), INT2NUM(bdb_stat->st_cur_offset)); rb_hash_aset(res, rb_tainted_str_new2("st_region_wait"), INT2NUM(bdb_stat->st_region_wait)); rb_hash_aset(res, rb_tainted_str_new2("st_region_nowait"), INT2NUM(bdb_stat->st_region_nowait)); #if HAVE_ST_DB_LOG_STAT_ST_DISK_FILE rb_hash_aset(res, rb_tainted_str_new2("st_disk_file"), INT2NUM(bdb_stat->st_disk_file)); #endif #if HAVE_ST_DB_LOG_STAT_ST_DISK_OFFSET rb_hash_aset(res, rb_tainted_str_new2("st_disk_offset"), INT2NUM(bdb_stat->st_disk_offset)); #if HAVE_ST_DB_LOG_STAT_ST_FLUSHCOMMIT rb_hash_aset(res, rb_tainted_str_new2("st_flushcommit"), INT2NUM(bdb_stat->st_flushcommit)); #endif #if HAVE_ST_DB_LOG_STAT_ST_MAXCOMMITPERFLUSH rb_hash_aset(res, rb_tainted_str_new2("st_maxcommitperflush"), INT2NUM(bdb_stat->st_maxcommitperflush)); #endif #if HAVE_ST_DB_LOG_STAT_ST_MINCOMMITPERFLUSH rb_hash_aset(res, rb_tainted_str_new2("st_mincommitperflush"), INT2NUM(bdb_stat->st_mincommitperflush)); #endif #endif free(bdb_stat); return res; }