Class: Bdb::Env

Inherits:
Object show all
Defined in:
ext/bdb.c,
ext/bdb.c

Overview

Encapsulated DB environment. Create by simple new (with flags as neede), then open. Database handles created with env.db -> Bdb::Db object.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.newObject

new(flags) -> object


1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
# File 'ext/bdb.c', line 1676

VALUE env_new(VALUE class, VALUE vflags)
{
  t_envh *eh;
  int rv;
  u_int32_t flags=0;
  VALUE obj;

  if ( ! NIL_P(vflags) )
    flags=NUM2UINT(vflags);

  obj=Data_Make_Struct(class,t_envh,env_mark,env_free,eh);
  rv=db_env_create(&(eh->env),flags);
  if ( rv != 0 ) {
    raise_error(rv,"env_new: %s",db_strerror(rv));
    return Qnil;
  }
  eh->self=obj;
  eh->adb = rb_ary_new();
  eh->atxn = rb_ary_new();
  rb_obj_call_init(obj,0,NULL);
  return obj;
}

Instance Method Details

#cachesizeObject

env.cachesize -> Fixnum|Bignum

return the environment cache size. If it is a Bignum then it will populate the bytes and gbytes part of the DB struct. Fixnums will only populate bytes (which is still pretty big).


1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
# File 'ext/bdb.c', line 1856

VALUE env_get_cachesize(VALUE obj)
{
  t_envh *eh;
  //unsigned long long ln;
  u_int32_t bytes=0,gbytes=0;
	int ncache;
  int rv;
  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");

  rv=eh->env->get_cachesize(eh->env,&gbytes,&bytes,&ncache);
  if ( rv != 0 ) {
    raise_error(rv, "get_cachesize failure: %s",db_strerror(rv));
    return Qnil;
  }

	if (gbytes != 0)
		return ULL2NUM(gbytes*1024*1024*1024+bytes);
	else
		return UINT2NUM(bytes);

  return Qtrue;
}

#cachesize=Object

env.cachesize=Fixnum|Bignum

set the environment cache size. If it is a Bignum then it will populate the bytes and gbytes part of the DB struct. Fixnums will only populate bytes (which is still pretty big).


1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
# File 'ext/bdb.c', line 1818

VALUE env_set_cachesize(VALUE obj, VALUE size)
{
  t_envh *eh;
  unsigned long long ln;
  u_int32_t bytes=0,gbytes=0;
  int rv;
  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");

  if ( TYPE(size) == T_BIGNUM ) {
    ln = rb_big2ull(size);
		gbytes = ln / (1024*1024*1024);
		bytes = ln - (gbytes*1024*1024*1024);
  } else if (FIXNUM_P(size) ) {
    bytes=NUM2UINT(size);
  } else {
    raise_error(0,"set_cachesize requires number");
    return Qnil;
  }

  rv=eh->env->set_cachesize(eh->env,gbytes,bytes,1);
  if ( rv != 0 ) {
    raise_error(rv, "set_cachesize failure: %s",db_strerror(rv));
    return Qnil;
  }

  return Qtrue;
}

#closeObject

env.close -> self

close an environment. Do not use it after you close it. The close process will automatically abort any open transactions and close open databases (which also closes open cursors). But this is just an effort to keep your dbs and envs from becoming corrupted due to ruby errors that exit unintentionally. However, to make this at all worth anything use ObjectSpace.define_finalizer which calls env.close to approach some assurance of it happening.


1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'ext/bdb.c', line 1747

VALUE env_close(VALUE obj)
{
  t_envh *eh;
  VALUE db;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if ( eh->env==NULL )
    return Qnil;

  if (RARRAY_LEN(eh->adb) > 0) {
    rb_warning("%s/%d %s %li",__FILE__,__LINE__,
	       "database handles still open",RARRAY_LEN(eh->adb));
    while (RARRAY_LEN(eh->adb) > 0)
      if ((db=rb_ary_pop(eh->adb)) != Qnil ) {
    rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,
           "closing",(void*)db);
      /* this could raise! needs rb_protect */
    db_close(db,INT2FIX(0));
      }
  }
  if (RARRAY_LEN(eh->atxn) > 0) {
    rb_warning("%s/%d %s",__FILE__,__LINE__,
	       "database transactions still open");
    while ( (db=rb_ary_pop(eh->atxn)) != Qnil ) {
      /* this could raise! needs rb_protect */
      txn_abort(db);
    }
  }

  if ( RTEST(ruby_debug) )
    rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"env_close!",(void*)eh);

  rv = eh->env->close(eh->env,NOFLAGS);
  eh->env=NULL;
  eh->adb=Qnil;
  eh->atxn=Qnil;
  if ( rv != 0 ) {
    raise_error(rv, "env_close failure: %s",db_strerror(rv));
    return Qnil;
  }
  return obj;
}

#data_dir=Object

env.set_data_dir(data_dir) -> data_dir

set data_dir


2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
# File 'ext/bdb.c', line 2710

VALUE env_set_data_dir(VALUE obj, VALUE vdata_dir)
{
  t_envh *eh;
  const char *data_dir;
  int rv;

  data_dir=StringValueCStr(vdata_dir);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_data_dir(eh->env,data_dir);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_data_dir: %s",db_strerror(rv));
  }

  return vdata_dir;
}

#data_dirsObject

env.get_data_dir -> [data_dir_1, data_dir_2, …]

get data_dir


2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
# File 'ext/bdb.c', line 2735

VALUE env_get_data_dirs(VALUE obj)
{
  t_envh *eh;
  const char **data_dirs;
  int rv;
	int ln;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_data_dirs(eh->env,&data_dirs);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_data_dir: %s",db_strerror(rv));
  }

	ln = (sizeof (data_dirs))/sizeof(data_dirs[0]);
	VALUE rb_data_dirs = rb_ary_new2(ln);
	int i;
	for (i=0; i<ln; i++) {
		rb_ary_push(rb_data_dirs, rb_str_new2(data_dirs[i]));
	}
	
  return rb_data_dirs;
}

#dbObject

env.db -> Bdb::Db instance

create a db associated with an environment


1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
# File 'ext/bdb.c', line 1797

VALUE env_db(VALUE obj)
{
  t_envh *eh;
  VALUE dbo;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  dbo = Data_Wrap_Struct(cDb,db_mark,db_free,0);

  return db_init_aux(dbo,eh);
}

#encrypt=Object

env.set_encrypt(passwd)

set encrypt


2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
# File 'ext/bdb.c', line 2904

VALUE env_set_encrypt(VALUE obj, VALUE vpasswd)
{
  t_envh *eh;
  const char *passwd;
  int rv;

  passwd = StringValueCStr(vpasswd);
  Data_Get_Struct(obj, t_envh, eh);
  u_int32_t flags=0x00000001; //DB_ENCRYPT_AES
  
  rv = eh->env->set_encrypt(eh->env, passwd, flags);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_encrypt: %s",db_strerror(rv));
  }

  return vpasswd;
}

#flagsObject

env.flags -> flags

get what flags are on.


1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
# File 'ext/bdb.c', line 1909

VALUE env_get_flags(VALUE obj)
{
  t_envh *eh;
  int rv;
  u_int32_t flags;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");

   rv=eh->env->get_flags(eh->env,&flags);

   if ( rv != 0 ) {
     raise_error(rv, "set_flags failure: %s",db_strerror(rv));
     return Qnil;
   }

  return UINT2NUM(flags);
}

#flags_off=Object

env.flags_off=flags

set the 'flags' off. An or'ed set of flags will be set off. Only included flags will be affected. Serialized calls will only affect flags indicated (leaving others, default or set as they were).


1952
1953
1954
1955
# File 'ext/bdb.c', line 1952

VALUE env_set_flags_off(VALUE obj, VALUE vflags)
{
  return env_set_flags(obj,vflags,0);
}

#flags_on=Object

env.flags_on=flags

set the 'flags' on. An or'ed set of flags will be set on. Only included flags will be affected. Serialized calls will only affect flags indicated (leaving others, default or set as they were).


1938
1939
1940
1941
# File 'ext/bdb.c', line 1938

VALUE env_set_flags_on(VALUE obj, VALUE vflags)
{
  return env_set_flags(obj,vflags,1);
}

#homeObject

env.get_home -> home

get home


2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
# File 'ext/bdb.c', line 2862

VALUE env_get_home(VALUE obj)
{
  t_envh *eh;
  const char *home;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_home(eh->env,&home);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_home: %s",db_strerror(rv));
  }

  return rb_str_new2(home);
}

#lg_bsizeObject


3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
# File 'ext/bdb.c', line 3111

VALUE env_get_lg_bsize( VALUE obj) {
	t_envh *eh;
	int rv;
	u_int32_t size;
	Data_Get_Struct( obj, t_envh, eh);
	rv = eh->env->get_lg_bsize( eh->env, &size);
  if ( rv != 0 )
		raise_error(rv, "env_get_lg_bsize: %s", db_strerror(rv));
  return UINT2FIX(size);
}

#lg_bsize=Object


3101
3102
3103
3104
3105
3106
3107
3108
3109
# File 'ext/bdb.c', line 3101

VALUE env_set_lg_bsize( VALUE obj, VALUE size) {
	t_envh *eh;
	int rv;
	Data_Get_Struct(obj, t_envh, eh);
	rv = eh->env->set_lg_bsize( eh->env, NUM2UINT( size));
  if ( rv != 0 )
		raise_error(rv, "env_set_lg_bsize: %s", db_strerror(rv));
  return size;
}

#lg_dirObject

env.get_lg_dir -> lg_dir

get lg_dir


2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
# File 'ext/bdb.c', line 2791

VALUE env_get_lg_dir(VALUE obj)
{
  t_envh *eh;
  const char *lg_dir;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_lg_dir(eh->env,&lg_dir);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_lg_dir: %s",db_strerror(rv));
  }

  return rb_str_new2(lg_dir);
}

#lg_dir=Object

env.set_lg_dir(lg_dir) -> lg_dir

set lg_dir


2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
# File 'ext/bdb.c', line 2766

VALUE env_set_lg_dir(VALUE obj, VALUE vlg_dir)
{
  t_envh *eh;
  const char *lg_dir;
  int rv;

  lg_dir=StringValueCStr(vlg_dir);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_lg_dir(eh->env,lg_dir);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_lg_dir: %s",db_strerror(rv));
  }

  return vlg_dir;
}

#lg_maxObject


3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
# File 'ext/bdb.c', line 3132

VALUE env_get_lg_max( VALUE obj) {
	t_envh *eh;
	int rv;
	u_int32_t size;
	Data_Get_Struct( obj, t_envh, eh);
	rv = eh->env->get_lg_max( eh->env, &size);
  if ( rv != 0 )
		raise_error(rv, "env_get_lg_max: %s", db_strerror(rv));
  return UINT2FIX(size);
}

#lg_max=Object


3122
3123
3124
3125
3126
3127
3128
3129
3130
# File 'ext/bdb.c', line 3122

VALUE env_set_lg_max( VALUE obj, VALUE size) {
	t_envh *eh;
	int rv;
	Data_Get_Struct(obj, t_envh, eh);
	rv = eh->env->set_lg_max( eh->env, NUM2UINT( size));
  if ( rv != 0 )
		raise_error(rv, "env_set_lg_max: %s", db_strerror(rv));
  return size;
}

#lg_regionmaxObject


3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
# File 'ext/bdb.c', line 3153

VALUE env_get_lg_regionmax( VALUE obj) {
	t_envh *eh;
	int rv;
	u_int32_t size;
	Data_Get_Struct( obj, t_envh, eh);
	rv = eh->env->get_lg_regionmax( eh->env, &size);
  if ( rv != 0 )
		raise_error(rv, "env_get_lg_regionmax: %s", db_strerror(rv));
  return UINT2FIX(size);
}

#lg_regionmax=Object


3143
3144
3145
3146
3147
3148
3149
3150
3151
# File 'ext/bdb.c', line 3143

VALUE env_set_lg_regionmax( VALUE obj, VALUE size) {
	t_envh *eh;
	int rv;
	Data_Get_Struct(obj, t_envh, eh);
	rv = eh->env->set_lg_regionmax( eh->env, NUM2UINT( size));
  if ( rv != 0 )
		raise_error(rv, "env_set_lg_regionmax: %s", db_strerror(rv));
  return size;
}

#list_dbsObject

env.list_dbs -> [Bdb::Db array]

return 0 or more open databases within the receiver environment. If 0, will return [], not nil.


1964
1965
1966
1967
1968
1969
1970
1971
# File 'ext/bdb.c', line 1964

VALUE env_list_dbs(VALUE obj)
{
  t_envh *eh;
  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  return eh->adb;
}

#lk_detectObject

env.get_lk_detect() -> detect

Get when lock detector should be run


2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
# File 'ext/bdb.c', line 2577

VALUE env_get_lk_detect(VALUE obj)
{
  t_envh *eh;
  u_int32_t detect;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_lk_detect(eh->env,&detect);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_lk_detect: %s",db_strerror(rv));
  }

  return UINT2NUM(detect);
}

#lk_detect=Object

env.set_lk_detect(detect) -> detect

Set when lock detector should be run


2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
# File 'ext/bdb.c', line 2552

VALUE env_set_lk_detect(VALUE obj, VALUE vdetect)
{
  t_envh *eh;
  u_int32_t detect;
  int rv;

  detect=NUM2UINT(vdetect);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_lk_detect(eh->env,detect);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_lk_detect: %s",db_strerror(rv));
  }

  return vdetect;
}

#lk_max_locksObject

env.get_lk_max_locks -> max

Get the maximum number of locks in the environment


2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
# File 'ext/bdb.c', line 2625

VALUE env_get_lk_max_locks(VALUE obj)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_lk_max_locks(eh->env,&max);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_lk_max_locks: %s",db_strerror(rv));
  }

  return UINT2NUM(max);
}

#lk_max_locks=Object

env.set_lk_max_locks(max) -> max

Set the maximum number of locks in the environment


2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
# File 'ext/bdb.c', line 2600

VALUE env_set_lk_max_locks(VALUE obj, VALUE vmax)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  max=FIX2UINT(vmax);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_lk_max_locks(eh->env,max);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_lk_max_locks: %s",db_strerror(rv));
  }

  return vmax;
}

#lk_max_objectsObject

env.get_lk_max_objects -> max

Get the maximum number of locks in the environment


2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
# File 'ext/bdb.c', line 2673

VALUE env_get_lk_max_objects(VALUE obj)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_lk_max_objects(eh->env,&max);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_lk_max_objects: %s",db_strerror(rv));
  }

  return UINT2NUM(max);
}

#lk_max_objects=Object

env.set_lk_max_objects(max) -> max

Set the maximum number of locks in the environment


2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
# File 'ext/bdb.c', line 2648

VALUE env_set_lk_max_objects(VALUE obj, VALUE vmax)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  max=FIX2UINT(vmax);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_lk_max_objects(eh->env,max);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_lk_max_objects: %s",db_strerror(rv));
  }

  return vmax;
}

#log_configObject


2540
2541
2542
2543
2544
# File 'ext/bdb.c', line 2540

ENV_LOG_CONFIG_FUNCS

VALUE env_log_set_config( VALUE obj, VALUE flags, VALUE onoff) {
	return env_log_set_config_h( obj, NUM2UINT(flags), onoff);
}

#mutex_get_maxObject

call-seq env.mutex_get_max -> Fixnum

Get current maximum number of mutexes.


2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
# File 'ext/bdb.c', line 2441

VALUE env_mutex_get_max(VALUE obj)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->mutex_get_max(eh->env,&max);
  if ( rv != 0 ) {
    raise_error(rv, "env_mutex_get_max: %s",db_strerror(rv));
  }

  return INT2FIX(max);
}

#mutex_set_maxObject

env.mutex_set_max(max) -> max

Set the maximum number of mutexes with the environment


2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
# File 'ext/bdb.c', line 2416

VALUE env_mutex_set_max(VALUE obj, VALUE vmax)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  max=FIX2UINT(vmax);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->mutex_set_max(eh->env,max);
  if ( rv != 0 ) {
    raise_error(rv, "env_mutex_set_max: %s",db_strerror(rv));
  }

  return vmax;
}

#openObject

env.open(homedir,flags,mode) -> self

open an environment


1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
# File 'ext/bdb.c', line 1705

VALUE env_open(VALUE obj, VALUE vhome, VALUE vflags, VALUE vmode)
{
  t_envh *eh;
  int rv;
  u_int32_t flags=0;
  int mode=0;

  if ( ! NIL_P(vflags) )
    flags=NUM2UINT(vflags);
  if ( ! NIL_P(vmode) )
    mode=NUM2INT(vmode);
  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  if ( NIL_P(eh->adb) )
    raise_error(0,"env handle already used and closed");

  rv = eh->env->open(eh->env,StringValueCStr(vhome),flags,mode);
  eh->env->app_private=eh;

  if (rv != 0) {
    raise_error(rv, "env_open failure: %s",db_strerror(rv));
  }
  return obj;
}

#rep_nsitesObject

env.rep_nsites -> int

returns the replication manager's acknowledgement policy


2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
# File 'ext/bdb.c', line 2981

VALUE env_rep_get_nsites(VALUE obj)
{
  t_envh *eh;
  u_int32_t nsites;

  Data_Get_Struct(obj,t_envh,eh);
  eh->env->rep_get_nsites(eh->env, &nsites);

  return INT2NUM(nsites);
}

#rep_nsites=Object

env.rep_nsites = int

specify how the replication manager will handle acknowledgement of replication messages


2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
# File 'ext/bdb.c', line 2963

VALUE env_rep_set_nsites(VALUE obj, VALUE nsites)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->rep_set_nsites(eh->env, NUM2UINT(nsites));

  if ( rv != 0 ) raise_error(rv, "env_rep_set_nsites: %s", db_strerror(rv));
  return nsites;
}

#rep_priorityObject

env.rep_priority -> int

returns the replication manager's acknowledgement policy


2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
# File 'ext/bdb.c', line 2946

VALUE env_rep_get_priority(VALUE obj)
{
  t_envh *eh;
  u_int32_t priority;

  Data_Get_Struct(obj,t_envh,eh);
  eh->env->rep_get_priority(eh->env, &priority);

  return INT2NUM(priority);
}

#rep_priority=Object

env.rep_priority = int

specify how the replication manager will handle acknowledgement of replication messages


2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
# File 'ext/bdb.c', line 2928

VALUE env_rep_set_priority(VALUE obj, VALUE priority)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->rep_set_priority(eh->env, NUM2UINT(priority));

  if ( rv != 0 ) raise_error(rv, "env_rep_set_priority: %s", db_strerror(rv));
  return priority;
}

#repmgr_ack_policyObject

env.repmgr_ack_policy -> int

returns the replication manager's acknowledgement policy


3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
# File 'ext/bdb.c', line 3054

VALUE env_repmgr_get_ack_policy(VALUE obj)
{
  t_envh *eh;
  int policy;

  Data_Get_Struct(obj,t_envh,eh);
  eh->env->repmgr_get_ack_policy(eh->env, &policy);

  return INT2NUM(policy);
}

#repmgr_ack_policy=Object

env.repmgr_ack_policy = int

specify how the replication manager will handle acknowledgement of replication messages


3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
# File 'ext/bdb.c', line 3036

VALUE env_repmgr_set_ack_policy(VALUE obj, VALUE policy)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->repmgr_set_ack_policy(eh->env, NUM2INT(policy));

  if ( rv != 0 ) raise_error(rv, "env_repmgr_set_ack_policy: %s", db_strerror(rv));
  return policy;
}

#repmgr_add_remote_siteObject

env.repmgr_add_remote_site(host, port)

add a remote for the replication manager


3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
# File 'ext/bdb.c', line 3017

VALUE env_repmgr_add_remote_site(VALUE obj, VALUE host, VALUE port)
{
  t_envh *eh;
  int rv;
  int eidp;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->repmgr_add_remote_site(eh->env, StringValuePtr(host), NUM2UINT(port), &eidp, 0);

  if ( rv != 0 ) raise_error(rv, "env_repmgr_add_remote_site: %s", db_strerror(rv));
  return INT2NUM(eidp);
}

#repmgr_set_local_siteObject

env.repmgr_set_local_site(host, port)

specify the local site for the replication manager


2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
# File 'ext/bdb.c', line 2999

VALUE env_repmgr_set_local_site(VALUE obj, VALUE host, VALUE port)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->repmgr_set_local_site(eh->env, StringValuePtr(host), NUM2UINT(port), 0);

  if ( rv != 0 ) raise_error(rv, "env_repmgr_set_local_site: %s", db_strerror(rv));
  return Qtrue;
}

#repmgr_startObject

env.repmgr_start(num_threads, flags)

start the replication manager


3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
# File 'ext/bdb.c', line 3071

VALUE env_repmgr_start(VALUE obj, VALUE num_threads, VALUE flags)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->repmgr_start(eh->env, NUM2INT(num_threads), NUM2UINT(flags));

  if ( rv != 0 ) raise_error(rv, "env_repmgr_start: %s", db_strerror(rv));
  return Qtrue;
}

#repmgr_stat_printObject

env.repmgr_stat_print

prints replication manager stats


3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
# File 'ext/bdb.c', line 3089

VALUE env_repmgr_stat_print(VALUE obj, VALUE flags)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->repmgr_stat_print(eh->env, NUM2UINT(flags));

  if ( rv != 0 ) raise_error(rv, "env_repmgr_stat_print: %s", db_strerror(rv));
  return Qtrue;
}

#report_stderrObject


2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
# File 'ext/bdb.c', line 2690

VALUE env_report_stderr(VALUE obj)
{
  t_envh *eh;
  //u_int32_t max;
  //int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  eh->env->set_errfile(eh->env,stderr);

  return Qtrue;
}

#set_verboseObject

env.set_verbose(which, onoff)

set verbose messages on or off


2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
# File 'ext/bdb.c', line 2885

VALUE env_set_verbose(VALUE obj, VALUE which, VALUE onoff)
{
  t_envh *eh;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  rv = eh->env->set_verbose(eh->env, NUM2UINT(which), RTEST(onoff));

  if ( rv != 0 )  raise_error(rv, "env_set_verbose: %s",db_strerror(rv));

  return Qtrue;
}

#shm_keyObject

call-seq env.get_shm_key -> Fixnum

Get the current shm key base


2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
# File 'ext/bdb.c', line 2489

VALUE env_get_shm_key(VALUE obj)
{
  t_envh *eh;
  long key;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_shm_key(eh->env,&key);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_shm_key: %s",db_strerror(rv));
  }

  return INT2FIX(key);
}

#shm_key=Object

env.set_shm_key(key) -> max

Set the shared memory key base


2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
# File 'ext/bdb.c', line 2464

VALUE env_set_shm_key(VALUE obj, VALUE vkey)
{
  t_envh *eh;
  long key;
  int rv;

  key=FIX2UINT(vkey);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_shm_key(eh->env,key);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_shm_key: %s",db_strerror(rv));
  }

  return vkey;
}

#timeoutObject

env.get_timeout(flags) -> Fixnum

Get current transaction and lock timeout value


2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
# File 'ext/bdb.c', line 2313

VALUE env_set_timeout(VALUE obj, VALUE vtimeout, VALUE vflags)
{
  t_envh *eh;
  u_int32_t flags=0;
  db_timeout_t timeout;
  int rv;

  if ( ! NIL_P(vflags))
    flags=NUM2UINT(vflags);
  timeout=FIX2UINT(vtimeout);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_timeout(eh->env,timeout,flags);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_timeout: %s",db_strerror(rv));
  }

  return vtimeout;
}

#tmp_dirObject

env.get_tmp_dir -> tmp_dir

get tmp_dir


2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
# File 'ext/bdb.c', line 2839

VALUE env_get_tmp_dir(VALUE obj)
{
  t_envh *eh;
  const char *tmp_dir;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_tmp_dir(eh->env,&tmp_dir);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_tmp_dir: %s",db_strerror(rv));
  }

  return rb_str_new2(tmp_dir);
}

#tmp_dir=Object

env.set_tmp_dir(tmp_dir) -> tmp_dir

set tmp_dir


2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
# File 'ext/bdb.c', line 2814

VALUE env_set_tmp_dir(VALUE obj, VALUE vtmp_dir)
{
  t_envh *eh;
  const char *tmp_dir;
  int rv;

  tmp_dir=StringValueCStr(vtmp_dir);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_tmp_dir(eh->env,tmp_dir);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_tmp_dir: %s",db_strerror(rv));
  }

  return vtmp_dir;
}

#tx_maxObject

call-seq env.get_tx_max -> Fixnum

Get current maximum number of transactions


2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
# File 'ext/bdb.c', line 2393

VALUE env_get_tx_max(VALUE obj)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->get_tx_max(eh->env,&max);
  if ( rv != 0 ) {
    raise_error(rv, "env_get_tx_max: %s",db_strerror(rv));
  }

  return INT2FIX(max);
}

#tx_max=Object

env.set_tx_max(max) -> max

Set the maximum number of transactions with the environment


2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
# File 'ext/bdb.c', line 2368

VALUE env_set_tx_max(VALUE obj, VALUE vmax)
{
  t_envh *eh;
  u_int32_t max;
  int rv;

  max=FIX2UINT(vmax);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->set_tx_max(eh->env,max);
  if ( rv != 0 ) {
    raise_error(rv, "env_set_tx_max: %s",db_strerror(rv));
  }

  return vmax;
}

#txn_beginObject

env.txn_begin(txn_parent,flags) -> Bdb::Txn

start a root transaction or embedded (via txn_parent).


2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
# File 'ext/bdb.c', line 2003

VALUE env_txn_begin(VALUE obj, VALUE vtxn_parent, VALUE vflags)
{
  t_txnh *parent=NULL, *txn=NULL;
  u_int32_t flags=0;
  int rv;
  t_envh *eh;
  VALUE t_obj;

  if ( ! NIL_P(vflags))
    flags=NUM2UINT(vflags);
  if ( ! NIL_P(vtxn_parent) ) {
    Data_Get_Struct(vtxn_parent,t_txnh,parent);
    if (!parent->txn)
        raise(0, "parent txn is closed");
  }

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  t_obj=Data_Make_Struct(cTxn,t_txnh,txn_mark,txn_free,txn);

  rv=eh->env->txn_begin(eh->env,parent?parent->txn:NULL,
			&(txn->txn),flags);

  if ( rv != 0 ) {
    raise_error(rv, "env_txn_begin: %s",db_strerror(rv));
    return Qnil;
  }
  txn->env=eh;
  txn->self=t_obj;
  rb_ary_push(eh->atxn,t_obj);

  /* Once we get this working, we'll have to track transactions */
  rb_obj_call_init(t_obj,0,NULL);
  return t_obj;
}

#txn_checkpointObject

env.txn_checkpoint -> true

Cause env transaction state to be checkpointed.


2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
# File 'ext/bdb.c', line 2046

VALUE env_txn_checkpoint(VALUE obj, VALUE vkbyte, VALUE vmin,
			 VALUE vflags)
{
  u_int32_t flags=0;
  int rv;
  t_envh *eh;
  u_int32_t kbyte=0, min=0;

  if ( ! NIL_P(vflags))
    flags=NUM2UINT(vflags);

  if ( FIXNUM_P(vkbyte) )
    kbyte=FIX2UINT(vkbyte);

  if ( FIXNUM_P(vmin) )
    min=FIX2UINT(vmin);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");
  rv=eh->env->txn_checkpoint(eh->env,kbyte,min,flags);
  if ( rv != 0 ) {
    raise_error(rv, "env_txn_checkpoint: %s",db_strerror(rv));
    return Qnil;
  }
  return Qtrue;
}

#txn_statObject

env.txn_stat -> Bdb::TxnStat

get the environment transaction status. Each active transaction will be contained within a Bdb::TxnStat::Active class.


2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
# File 'ext/bdb.c', line 2244

VALUE env_txn_stat(VALUE obj, VALUE vflags)
{
  u_int32_t flags=0;
  int rv;
  t_envh *eh;
  DB_TXN_STAT *statp;
  VALUE s_obj;
  VALUE active;
  int i;

  if ( ! NIL_P(vflags))
    flags=NUM2UINT(vflags);

  Data_Get_Struct(obj,t_envh,eh);
  if (!eh->env)
    raise(0, "env is closed");

  /* statp will need free() */
  rv=eh->env->txn_stat(eh->env,&statp,flags);
  if ( rv != 0 ) {
    raise_error(rv, "txn_stat: %s",db_strerror(rv));
  }
  
  s_obj=rb_class_new_instance(0,NULL,cTxnStat);
  rb_iv_set(s_obj,"@st_last_ckp",
	    rb_ary_new3(2,
			INT2FIX(statp->st_last_ckp.file),
			INT2FIX(statp->st_last_ckp.offset)) );
  rb_iv_set(s_obj,"@st_time_ckp",
	    rb_time_new(statp->st_time_ckp,0));
  rb_iv_set(s_obj,"@st_last_txnid",
	    INT2FIX(statp->st_last_txnid));
  rb_iv_set(s_obj,"@st_maxtxns",
	    INT2FIX(statp->st_maxtxns));
  rb_iv_set(s_obj,"@st_nactive",
	    INT2FIX(statp->st_nactive));
  rb_iv_set(s_obj,"@st_maxnactive",
	    INT2FIX(statp->st_maxnactive));
  rb_iv_set(s_obj,"@st_nbegins",
	    INT2FIX(statp->st_nbegins));
  rb_iv_set(s_obj,"@st_naborts",
	    INT2FIX(statp->st_naborts));
  rb_iv_set(s_obj,"@st_ncommits",
	    INT2FIX(statp->st_ncommits));
  rb_iv_set(s_obj,"@st_nrestores",
	    INT2FIX(statp->st_nrestores));
  rb_iv_set(s_obj,"@st_regsize",
	    INT2FIX(statp->st_regsize));
  rb_iv_set(s_obj,"@st_region_wait",
	    INT2FIX(statp->st_region_wait));
  rb_iv_set(s_obj,"@st_region_nowait",
	    INT2FIX(statp->st_region_nowait));
  rb_iv_set(s_obj,"@st_txnarray",
	    active=rb_ary_new2(statp->st_nactive));

  for (i=0; i<statp->st_nactive; i++) {
    rb_ary_push(active,env_txn_stat_active(&(statp->st_txnarray[i])));
  }

  free(statp);
  return s_obj;
}