bdb 0.2.2 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1,2 @@
1
+ Justin Balthrop code.at.justinbalthrop.dot.com
2
+ Denis Knauf denis.dot.knauf.at.gmail.dot.com
@@ -0,0 +1,92 @@
1
+ Description
2
+ ===
3
+
4
+ Ruby bindings for Berkeley DB versions 4.2-4.8.
5
+
6
+ Installation
7
+ ============
8
+
9
+ From Git
10
+ --------
11
+
12
+ You can check out the latest source from git:
13
+
14
+ git clone git://github.com/DenisKnauf/bdb.git
15
+
16
+ As a Gem
17
+ ========
18
+
19
+ At the moment this library is not available on Rubyforge. To install it as a
20
+ gem, do the following:
21
+
22
+ sudo gem install dk-bdb
23
+
24
+ For Berkeley DB v4.7 installed from MacPorts do the following:
25
+
26
+ sudo env ARCHFLAGS="-arch i386" gem install dk-bdb
27
+
28
+ This assumes you're on OS X and BerkeleyDB wasn't compiled as a universal binary.
29
+
30
+ Sample Usage
31
+ ============
32
+
33
+ env = Bdb::Env.new(0)
34
+ env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist.
35
+ Bdb::DB_INIT_TXN | # Initialize transactions
36
+ Bdb::DB_INIT_LOCK | # Initialize locking.
37
+ Bdb::DB_INIT_LOG | # Initialize logging
38
+ Bdb::DB_INIT_MPOOL # Initialize the in-memory cache.
39
+ env.open(File.join(File.dirname(__FILE__), 'tmp'), env_flags, 0);
40
+
41
+ db = env.db
42
+ db.open(nil, 'db1.db', nil, Bdb::Db::BTREE, Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, 0)
43
+
44
+ txn = env.txn_begin(nil, 0)
45
+ db.put(txn, 'key', 'value', 0)
46
+ txn.commit(0)
47
+
48
+ value = db.get(nil, 'key', nil, 0)
49
+
50
+ db.close(0)
51
+ env.close
52
+
53
+ API
54
+ ===
55
+
56
+ This interface is most closely based on the DB4 C api and tries to maintain close
57
+ interface proximity.
58
+ [That API is published by Oracle](http://www.oracle.com/technology/documentation/berkeley-db/db/api_reference/C/frame_main.html).
59
+
60
+ All function arguments systematically omit the leading DB handles and TXN handles.
61
+ A few calls omit the flags parameter when the documentation indicates that no
62
+ flag values are used - cursor.close is one.
63
+
64
+ Alternative API
65
+ ---------------
66
+
67
+ You can use [SBDB](http://github.com/DenisKnauf/sbdb), too. It is easier to use, but base on this library.
68
+
69
+ Notes
70
+ =====
71
+
72
+ The defines generator is imperfect and includes some defines that are not
73
+ flags. While it could be improved, it is easier to delete the incorrect ones.
74
+ Thus, if you decide to rebuild the defines, you will need to edit the resulting
75
+ file. This may be necessary if using a different release of DB4 than the ones
76
+ the authors developed against. In nearly every case the defines generator works
77
+ flawlessly.
78
+
79
+ The authors have put all possible caution into ensuring that DB and Ruby cooperate.
80
+ The memory access was one aspect carefully considered. Since Ruby copies
81
+ when doing String#new, all key/data retrieval from DB is done with a 0 flag,
82
+ meaning that DB will be responsible. See [*this* news group posting](http://groups.google.com/group/comp.databases.berkeley-db/browse_frm/thread/4f70a9999b64ce6a/c06b94692e3cbc41?tvc=1&q=dbt+malloc#c06b94692e3cbc41)
83
+ about the effect of that.
84
+
85
+ The only other design consideration of consequence was associate. The prior
86
+ version used a Ruby thread local variable and kept track of the current
87
+ database in use. The authors decided to take a simpler approach since Ruby is green
88
+ threads. A global array stores the VALUE of the Proc for a given association
89
+ by the file descriptor number of the underlying database. This is looked
90
+ up when the first layer callback is made. It would have been better considered
91
+ if DB allowed the passing of a (void *) user data into the alloc that would
92
+ be supplied during callback. So far this design has not produced any problems.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.5
data/ext/bdb.c CHANGED
@@ -32,6 +32,24 @@ VALUE eDbError;
32
32
 
33
33
  static ID fv_call,fv_uniq,fv_err_new,fv_err_code,fv_err_msg;
34
34
 
35
+ #define EXCEPTIONS_CREATE \
36
+ eDbE_create(BUFFER_SMALL, BufferSmall)\
37
+ eDbE_create(LOCK_DEADLOCK, LockDeadlock)\
38
+ eDbE_create(LOCK_NOTGRANTED, LockNotgranted)\
39
+ eDbE_create(REP_HANDLE_DEAD, RepHandleDead)\
40
+ eDbE_create(REP_LEASE_EXPIRED, RepLeaseExpired)\
41
+ eDbE_create(REP_LOCKOUT, RepLockout)\
42
+ eDbE_create(SECONDARY_BAD, SecondaryBad) \
43
+ eDbE_create(FOREIGN_CONFLICT, ForeignConflict) \
44
+ eDbE_create(OLD_VERSION, OldVersion) \
45
+ eDbE_create(KEYEXIST, KeyExist) \
46
+ eDbE_create(KEYEMPTY, KeyEmpty) \
47
+ eDbE_create(RUNRECOVERY, RunRecovery) \
48
+ eDbE_create(VERSION_MISMATCH, VersionMismatch)
49
+
50
+ #define eDbE_create(n,c) VALUE eDbE_##c;
51
+ EXCEPTIONS_CREATE
52
+
35
53
  /*
36
54
  * Document-class: Bdb::DbError
37
55
  *
@@ -61,8 +79,14 @@ raise_error(int code, const char *fmt, ...)
61
79
 
62
80
  argv[0]=rb_str_new2(buf);
63
81
  argv[1]=INT2NUM(code);
82
+ VALUE cl;
83
+ switch( code) {
84
+ #define eDbE_create(n,c) case DB_##n: cl = eDbE_##c; break;
85
+ EXCEPTIONS_CREATE
86
+ default: cl = eDbError; break;
87
+ }
64
88
 
65
- exc=rb_class_new_instance(2,argv,eDbError);
89
+ exc=rb_class_new_instance(2,argv,cl);
66
90
  rb_exc_raise(exc);
67
91
  }
68
92
 
@@ -100,7 +124,7 @@ static void db_free(t_dbh *dbh)
100
124
  dbh->db->close(dbh->db,NOFLAGS);
101
125
  if ( RTEST(ruby_debug) && dbh->filename[0] != '\0')
102
126
  fprintf(stderr,"%s/%d %s %p %s\n",__FILE__,__LINE__,
103
- "db_free database was still open!",dbh->db,dbh->filename);
127
+ "db_free database was still open!",(void*)dbh->db,dbh->filename);
104
128
  dbh->db=NULL;
105
129
  }
106
130
  free(dbh);
@@ -230,7 +254,7 @@ VALUE db_open(VALUE obj, VALUE vtxn, VALUE vdisk_file,
230
254
  u_int32_t flags=0;
231
255
  DBTYPE dbtype=DB_UNKNOWN;
232
256
  char *logical_db=NULL;
233
- long len;
257
+ //long len;
234
258
  int mode=0;
235
259
 
236
260
  if ( ! NIL_P(vflags) )
@@ -279,6 +303,36 @@ VALUE db_open(VALUE obj, VALUE vtxn, VALUE vdisk_file,
279
303
  return obj;
280
304
  }
281
305
 
306
+ /**
307
+ * call-seq:
308
+ * db.set_re_len( db, re_len)
309
+ *
310
+ * Set record-length
311
+ */
312
+ VALUE db_set_re_len(VALUE obj, VALUE re_len) {
313
+ int rv;
314
+ t_dbh *dbh;
315
+ Data_Get_Struct(obj,t_dbh,dbh);
316
+ if (!dbh->db)
317
+ raise_error(0,"db isn't created");
318
+ rv = dbh->db->set_re_len(dbh->db,NUM2UINT(re_len));
319
+ if ( rv != 0 )
320
+ raise_error(rv, "set_re_len failure: %s",db_strerror(rv));
321
+ return re_len;
322
+ }
323
+
324
+ VALUE db_get_re_len( VALUE obj) {
325
+ u_int32_t re_len;
326
+ t_dbh *dbh;
327
+ Data_Get_Struct(obj,t_dbh,dbh);
328
+ if (!dbh->db)
329
+ raise_error(0,"db isn't created");
330
+ int rv = dbh->db->get_re_len(dbh->db,&re_len);
331
+ if ( rv != 0 )
332
+ raise_error(rv, "db_get_re_len failure: %s",db_strerror(rv));
333
+ return UINT2NUM(re_len);
334
+ }
335
+
282
336
  /*
283
337
  * call-seq:
284
338
  * db.flags=value
@@ -498,7 +552,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
498
552
  if ( dbh->db==NULL )
499
553
  return Qnil;
500
554
 
501
- if (! NIL_P(dbh->adbc) && RARRAY(dbh->adbc)->len > 0 ) {
555
+ if (! NIL_P(dbh->adbc) && RARRAY_LEN(dbh->adbc) > 0 ) {
502
556
  rb_warning("%s/%d %s",__FILE__,__LINE__,
503
557
  "cursor handles still open");
504
558
  while ( (cur=rb_ary_pop(dbh->adbc)) != Qnil ) {
@@ -507,8 +561,8 @@ VALUE db_close(VALUE obj, VALUE vflags)
507
561
  }
508
562
 
509
563
  if ( RTEST(ruby_debug) )
510
- rb_warning("%s/%d %s 0x%x %s",__FILE__,__LINE__,"db_close!",dbh,
511
- (dbh->filename==NULL||*(dbh->filename)=='0') ? "unknown" : dbh->filename);
564
+ rb_warning("%s/%d %s 0x%p %s",__FILE__,__LINE__,"db_close!", (void*)dbh,
565
+ (dbh->filename==NULL||*(dbh->filename)=='0') ? (char*)"unknown" : dbh->filename);
512
566
 
513
567
  rv = dbh->db->close(dbh->db,flags);
514
568
  dbh->db=NULL;
@@ -516,7 +570,7 @@ VALUE db_close(VALUE obj, VALUE vflags)
516
570
  dbh->sproc=Qnil;
517
571
  if ( dbh->env ) {
518
572
  if ( RTEST(ruby_debug) )
519
- rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"db_close! removing",obj);
573
+ rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"db_close! removing",(void*)obj);
520
574
  rb_ary_delete(dbh->env->adb,obj);
521
575
  dbh->env = NULL;
522
576
  }
@@ -559,10 +613,9 @@ VALUE db_put(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vdata, VALUE vflags)
559
613
  if (!dbh->db)
560
614
  raise_error(0,"db is closed");
561
615
 
562
- StringValue(vkey);
563
- key.data = RSTRING_PTR(vkey);
564
- key.size = RSTRING_LEN(vkey);
565
- key.flags = LMEMFLAG;
616
+ key.data = RSTRING_PTR(vkey);
617
+ key.size = RSTRING_LEN(vkey);
618
+ key.flags = LMEMFLAG;
566
619
 
567
620
  StringValue(vdata);
568
621
  data.data = RSTRING_PTR(vdata);
@@ -577,6 +630,13 @@ VALUE db_put(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vdata, VALUE vflags)
577
630
  if (rv != 0) {
578
631
  raise_error(rv, "db_put fails: %s",db_strerror(rv));
579
632
  }
633
+
634
+ if ( flags & DB_APPEND == DB_APPEND ) {
635
+ VALUE str = rb_str_new(key.data,key.size);
636
+ if (key.data) free(key.data);
637
+ return str;
638
+ }
639
+
580
640
  return obj;
581
641
  }
582
642
 
@@ -654,7 +714,7 @@ VALUE db_pget(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vdata, VALUE vflags)
654
714
  int rv;
655
715
  u_int32_t flags=0;
656
716
  DBT key,data,pkey;
657
- VALUE str;
717
+ //VALUE str;
658
718
  t_txnh *txn=NULL;
659
719
 
660
720
  memset(&key,0,sizeof(DBT));
@@ -749,9 +809,9 @@ VALUE db_join(VALUE obj, VALUE vacurs, VALUE vflags)
749
809
  if (!dbh->db)
750
810
  raise(0, "db is closed");
751
811
 
752
- curs = ALLOCA_N(DBC *,RARRAY(vacurs)->len);
753
- for (i=0; i<RARRAY(vacurs)->len; i++) {
754
- Data_Get_Struct(RARRAY(vacurs)->ptr[i],t_dbch,dbch);
812
+ curs = ALLOCA_N(DBC *,RARRAY_LEN(vacurs));
813
+ for (i=0; i<RARRAY_LEN(vacurs); i++) {
814
+ Data_Get_Struct(RARRAY_PTR(vacurs)[i],t_dbch,dbch);
755
815
  /* cursor is closed? */
756
816
  curs[i]=dbch->dbc;
757
817
  }
@@ -767,7 +827,7 @@ VALUE db_join(VALUE obj, VALUE vacurs, VALUE vflags)
767
827
  return jcurs;
768
828
  }
769
829
 
770
- #if DB_VERSION_MINOR > 3
830
+ #if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 3
771
831
  /*
772
832
  * call-seq:
773
833
  * db.compact(txn,start_key,stop_key,compact_opts,flags) -> end_key
@@ -890,7 +950,7 @@ VALUE db_remove(VALUE obj, VALUE vdisk_file,
890
950
  t_dbh *dbh;
891
951
  int rv;
892
952
  u_int32_t flags=0;
893
- char *logical_db=NULL;
953
+ //char *logical_db=NULL;
894
954
 
895
955
  if ( ! NIL_P(vflags) )
896
956
  flags=NUM2UINT(vflags);
@@ -921,8 +981,8 @@ VALUE db_rename(VALUE obj, VALUE vdisk_file,
921
981
  t_dbh *dbh;
922
982
  int rv;
923
983
  u_int32_t flags=0;
924
- char *disk_file=NULL;
925
- char *logical_db=NULL;
984
+ //char *disk_file=NULL;
985
+ //char *logical_db=NULL;
926
986
 
927
987
  if ( ! NIL_P(vflags) )
928
988
  flags=NUM2UINT(vflags);
@@ -978,7 +1038,7 @@ VALUE db_truncate(VALUE obj, VALUE vtxn)
978
1038
  t_dbh *dbh;
979
1039
  t_txnh *txn=NULL;
980
1040
  int rv;
981
- VALUE result;
1041
+ //VALUE result;
982
1042
  u_int32_t count;
983
1043
 
984
1044
  if ( ! NIL_P(vtxn) ) {
@@ -1011,7 +1071,7 @@ VALUE db_key_range(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags)
1011
1071
  t_dbh *dbh;
1012
1072
  t_txnh *txn=NULL;
1013
1073
  DBT key;
1014
- u_int32_t flags;
1074
+ u_int32_t flags = 0;
1015
1075
  int rv;
1016
1076
  DB_KEY_RANGE key_range;
1017
1077
  VALUE result;
@@ -1062,7 +1122,7 @@ VALUE db_del(VALUE obj, VALUE vtxn, VALUE vkey, VALUE vflags)
1062
1122
  int rv;
1063
1123
  u_int32_t flags;
1064
1124
  DBT key;
1065
- VALUE str;
1125
+ //VALUE str;
1066
1126
  t_txnh *txn=NULL;
1067
1127
 
1068
1128
  memset(&key,0,sizeof(DBT));
@@ -1117,12 +1177,13 @@ VALUE assoc_rescue(VALUE *error, VALUE e)
1117
1177
  VALUE message = StringValue(e);
1118
1178
  rb_warn(RSTRING_PTR(message));
1119
1179
  *error = e;
1180
+ return Qnil;
1120
1181
  }
1121
1182
 
1122
1183
  int assoc_callback(DB *secdb, const DBT* pkey, const DBT* data, DBT* skey)
1123
1184
  {
1124
1185
  t_dbh *dbh;
1125
- VALUE proc;
1186
+ //VALUE proc;
1126
1187
  VALUE error = Qnil;
1127
1188
  VALUE retv;
1128
1189
  VALUE args[4];
@@ -1150,20 +1211,20 @@ int assoc_callback(DB *secdb, const DBT* pkey, const DBT* data, DBT* skey)
1150
1211
  keys = rb_check_array_type(retv);
1151
1212
  if (!NIL_P(keys)) {
1152
1213
  keys = rb_funcall(keys,fv_uniq,0); /* secondary keys must be uniq */
1153
- switch(RARRAY(keys)->len) {
1214
+ switch(RARRAY_LEN(keys)) {
1154
1215
  case 0:
1155
1216
  return DB_DONOTINDEX;
1156
1217
  case 1:
1157
- retv=RARRAY(keys)->ptr[0];
1218
+ retv=RARRAY_PTR(keys)[0];
1158
1219
  break;
1159
1220
  default:
1160
- skey->size = RARRAY(keys)->len;
1221
+ skey->size = RARRAY_LEN(keys);
1161
1222
  skey->flags = LMEMFLAG | DB_DBT_MULTIPLE | DB_DBT_APPMALLOC;
1162
1223
  skey->data = malloc(skey->size * sizeof(DBT));
1163
1224
  memset(skey->data, 0, skey->size * sizeof(DBT));
1164
1225
 
1165
1226
  for (i=0; i<skey->size; i++) {
1166
- assoc_key(skey->data + i * sizeof(DBT), (VALUE)RARRAY(keys)->ptr[i]);
1227
+ assoc_key(skey->data + i * sizeof(DBT), (VALUE)RARRAY_PTR(keys)[i]);
1167
1228
  }
1168
1229
  return 0;
1169
1230
  }
@@ -1190,7 +1251,7 @@ VALUE db_associate(VALUE obj, VALUE vtxn, VALUE osecdb,
1190
1251
  t_dbh *sdbh,*pdbh;
1191
1252
  int rv;
1192
1253
  u_int32_t flags,flagsp,flagss;
1193
- int fdp;
1254
+ //int fdp;
1194
1255
  t_txnh *txn=NOTXN;
1195
1256
 
1196
1257
  flags=NUM2UINT(vflags);
@@ -1246,7 +1307,7 @@ bt_compare_callback2(VALUE *args)
1246
1307
  int bt_compare_callback(DB *db, const DBT* key1, const DBT* key2)
1247
1308
  {
1248
1309
  t_dbh *dbh;
1249
- VALUE proc;
1310
+ //VALUE proc;
1250
1311
  int cmp;
1251
1312
  VALUE retv;
1252
1313
 
@@ -1313,7 +1374,7 @@ VALUE db_cursor(VALUE obj, VALUE vtxn, VALUE vflags)
1313
1374
  t_dbh *dbh;
1314
1375
  int rv;
1315
1376
  u_int32_t flags;
1316
- DBC *dbc;
1377
+ //DBC *dbc;
1317
1378
  t_txnh *txn=NOTXN;
1318
1379
  VALUE c_obj;
1319
1380
  t_dbch *dbch;
@@ -1671,18 +1732,18 @@ VALUE env_close(VALUE obj)
1671
1732
  if ( eh->env==NULL )
1672
1733
  return Qnil;
1673
1734
 
1674
- if (RARRAY(eh->adb)->len > 0) {
1675
- rb_warning("%s/%d %s %d",__FILE__,__LINE__,
1676
- "database handles still open",RARRAY(eh->adb)->len);
1677
- while (RARRAY(eh->adb)->len > 0)
1735
+ if (RARRAY_LEN(eh->adb) > 0) {
1736
+ rb_warning("%s/%d %s %li",__FILE__,__LINE__,
1737
+ "database handles still open",RARRAY_LEN(eh->adb));
1738
+ while (RARRAY_LEN(eh->adb) > 0)
1678
1739
  if ((db=rb_ary_pop(eh->adb)) != Qnil ) {
1679
- rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,
1680
- "closing",db);
1740
+ rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,
1741
+ "closing",(void*)db);
1681
1742
  /* this could raise! needs rb_protect */
1682
1743
  db_close(db,INT2FIX(0));
1683
1744
  }
1684
1745
  }
1685
- if (RARRAY(eh->atxn)->len > 0) {
1746
+ if (RARRAY_LEN(eh->atxn) > 0) {
1686
1747
  rb_warning("%s/%d %s",__FILE__,__LINE__,
1687
1748
  "database transactions still open");
1688
1749
  while ( (db=rb_ary_pop(eh->atxn)) != Qnil ) {
@@ -1692,7 +1753,7 @@ VALUE env_close(VALUE obj)
1692
1753
  }
1693
1754
 
1694
1755
  if ( RTEST(ruby_debug) )
1695
- rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"env_close!",eh);
1756
+ rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"env_close!",(void*)eh);
1696
1757
 
1697
1758
  rv = eh->env->close(eh->env,NOFLAGS);
1698
1759
  eh->env=NULL;
@@ -1773,7 +1834,7 @@ VALUE env_set_cachesize(VALUE obj, VALUE size)
1773
1834
  VALUE env_get_cachesize(VALUE obj)
1774
1835
  {
1775
1836
  t_envh *eh;
1776
- unsigned long long ln;
1837
+ //unsigned long long ln;
1777
1838
  u_int32_t bytes=0,gbytes=0;
1778
1839
  int ncache;
1779
1840
  int rv;
@@ -2044,7 +2105,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
2044
2105
  rv=dbh->db->get_type(dbh->db,&dbtype);
2045
2106
  if (rv)
2046
2107
  raise_error(rv,"db_stat %s",db_strerror(rv));
2047
- #if DB_VERSION_MINOR > 2
2108
+ #if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 2
2048
2109
  rv=dbh->db->stat(dbh->db,txn?txn->txn:NULL,&(su.stat),flags);
2049
2110
  #else
2050
2111
  rv=dbh->db->stat(dbh->db,&(su.stat),flags);
@@ -2090,7 +2151,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
2090
2151
  bs_int(bt_nkeys); /* Number of unique keys. */
2091
2152
  bs_int(bt_ndata); /* Number of data items. */
2092
2153
  bs_int(bt_pagesize); /* Page size. */
2093
- #if DB_VERSION_MINOR < 4
2154
+ #if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4
2094
2155
  bs_int(bt_maxkey); /* Maxkey value. */
2095
2156
  #endif
2096
2157
  bs_int(bt_minkey); /* Minkey value. */
@@ -2101,7 +2162,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
2101
2162
  bs_int(bt_leaf_pg); /* Leaf pages. */
2102
2163
  bs_int(bt_dup_pg); /* Duplicate pages. */
2103
2164
  bs_int(bt_over_pg); /* Overflow pages. */
2104
- #if DB_VERSION_MINOR > 2
2165
+ #if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 2
2105
2166
  bs_int(bt_empty_pg); /* Empty pages. */
2106
2167
  #endif
2107
2168
  bs_int(bt_free); /* Pages on the free list. */
@@ -2131,6 +2192,8 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
2131
2192
  qs_int(qs_cur_recno); /* Next available record number. */
2132
2193
 
2133
2194
  break;
2195
+ case DB_UNKNOWN:
2196
+ break;
2134
2197
  }
2135
2198
 
2136
2199
  free(su.stat);
@@ -2145,7 +2208,7 @@ VALUE db_stat(VALUE obj, VALUE vtxn, VALUE vflags)
2145
2208
  */
2146
2209
  VALUE stat_aref(VALUE obj, VALUE vname)
2147
2210
  {
2148
- rb_iv_get(obj,RSTRING_PTR(rb_str_concat(rb_str_new2("@"),vname)));
2211
+ return rb_iv_get(obj,RSTRING_PTR(rb_str_concat(rb_str_new2("@"),vname)));
2149
2212
  }
2150
2213
 
2151
2214
  /*
@@ -2418,6 +2481,46 @@ VALUE env_get_shm_key(VALUE obj)
2418
2481
  return INT2FIX(key);
2419
2482
  }
2420
2483
 
2484
+ VALUE env_log_set_config_h(VALUE obj, u_int32_t flags, VALUE onoff) {
2485
+ t_envh *eh;
2486
+ int rv;
2487
+ Data_Get_Struct(obj,t_envh, eh);
2488
+ rv=eh->env->log_set_config(eh->env, flags, Qnil != flags && Qfalse != onoff);
2489
+ if(rv != 0)
2490
+ raise_error(rv, "log_set_config: %s", db_strerror(rv));
2491
+ return flags;
2492
+ }
2493
+
2494
+ VALUE env_log_get_config_h( VALUE obj, u_int32_t flags) {
2495
+ t_envh *eh;
2496
+ int rv, onoff;
2497
+ Data_Get_Struct(obj,t_envh, eh);
2498
+ rv=eh->env->log_get_config(eh->env, flags, &onoff);
2499
+ if(rv != 0)
2500
+ raise_error(rv, "log_set_config: %s", db_strerror(rv));
2501
+ return onoff ? Qtrue : Qfalse;
2502
+ }
2503
+
2504
+ #define ENV_LOG_CONFIG_FUNCS \
2505
+ ENV_LOG_CONFIG_FUNC(direct,DIRECT) \
2506
+ ENV_LOG_CONFIG_FUNC(dsync,DSYNC) \
2507
+ ENV_LOG_CONFIG_FUNC(auto_remove,AUTO_REMOVE) \
2508
+ ENV_LOG_CONFIG_FUNC(in_memory,IN_MEMORY) \
2509
+ ENV_LOG_CONFIG_FUNC(zero,ZERO)
2510
+
2511
+ #define ENV_LOG_CONFIG_FUNC( name, cnst) \
2512
+ VALUE env_log_set_##cnst( VALUE obj, VALUE flags) { \
2513
+ return env_log_set_config_h( obj, DB_LOG_##cnst, flags); \
2514
+ } \
2515
+ VALUE env_log_get_##cnst( VALUE obj, VALUE flags) { \
2516
+ return env_log_get_config_h( obj, DB_LOG_##cnst); \
2517
+ }
2518
+ ENV_LOG_CONFIG_FUNCS
2519
+
2520
+ VALUE env_log_set_config( VALUE obj, VALUE flags, VALUE onoff) {
2521
+ return env_log_set_config_h( obj, NUM2UINT(flags), onoff);
2522
+ }
2523
+
2421
2524
  /*
2422
2525
  * call-seq:
2423
2526
  * env.set_lk_detect(detect) -> detect
@@ -2565,8 +2668,8 @@ VALUE env_get_lk_max_objects(VALUE obj)
2565
2668
  VALUE env_report_stderr(VALUE obj)
2566
2669
  {
2567
2670
  t_envh *eh;
2568
- u_int32_t max;
2569
- int rv;
2671
+ //u_int32_t max;
2672
+ //int rv;
2570
2673
 
2571
2674
  Data_Get_Struct(obj,t_envh,eh);
2572
2675
  if (!eh->env)
@@ -2949,11 +3052,74 @@ VALUE env_repmgr_stat_print(VALUE obj, VALUE flags)
2949
3052
  return Qtrue;
2950
3053
  }
2951
3054
 
3055
+ VALUE env_set_lg_bsize( VALUE obj, VALUE size) {
3056
+ t_envh *eh;
3057
+ int rv;
3058
+ Data_Get_Struct(obj, t_envh, eh);
3059
+ rv = eh->env->set_lg_bsize( eh->env, NUM2UINT( size));
3060
+ if ( rv != 0 )
3061
+ raise_error(rv, "env_set_lg_bsize: %s", db_strerror(rv));
3062
+ return size;
3063
+ }
3064
+
3065
+ VALUE env_get_lg_bsize( VALUE obj) {
3066
+ t_envh *eh;
3067
+ int rv;
3068
+ u_int32_t size;
3069
+ Data_Get_Struct( obj, t_envh, eh);
3070
+ rv = eh->env->get_lg_bsize( eh->env, &size);
3071
+ if ( rv != 0 )
3072
+ raise_error(rv, "env_get_lg_bsize: %s", db_strerror(rv));
3073
+ return UINT2FIX(size);
3074
+ }
3075
+
3076
+ VALUE env_set_lg_max( VALUE obj, VALUE size) {
3077
+ t_envh *eh;
3078
+ int rv;
3079
+ Data_Get_Struct(obj, t_envh, eh);
3080
+ rv = eh->env->set_lg_max( eh->env, NUM2UINT( size));
3081
+ if ( rv != 0 )
3082
+ raise_error(rv, "env_set_lg_max: %s", db_strerror(rv));
3083
+ return size;
3084
+ }
3085
+
3086
+ VALUE env_get_lg_max( VALUE obj) {
3087
+ t_envh *eh;
3088
+ int rv;
3089
+ u_int32_t size;
3090
+ Data_Get_Struct( obj, t_envh, eh);
3091
+ rv = eh->env->get_lg_max( eh->env, &size);
3092
+ if ( rv != 0 )
3093
+ raise_error(rv, "env_get_lg_max: %s", db_strerror(rv));
3094
+ return UINT2FIX(size);
3095
+ }
3096
+
3097
+ VALUE env_set_lg_regionmax( VALUE obj, VALUE size) {
3098
+ t_envh *eh;
3099
+ int rv;
3100
+ Data_Get_Struct(obj, t_envh, eh);
3101
+ rv = eh->env->set_lg_regionmax( eh->env, NUM2UINT( size));
3102
+ if ( rv != 0 )
3103
+ raise_error(rv, "env_set_lg_regionmax: %s", db_strerror(rv));
3104
+ return size;
3105
+ }
3106
+
3107
+ VALUE env_get_lg_regionmax( VALUE obj) {
3108
+ t_envh *eh;
3109
+ int rv;
3110
+ u_int32_t size;
3111
+ Data_Get_Struct( obj, t_envh, eh);
3112
+ rv = eh->env->get_lg_regionmax( eh->env, &size);
3113
+ if ( rv != 0 )
3114
+ raise_error(rv, "env_get_lg_regionmax: %s", db_strerror(rv));
3115
+ return UINT2FIX(size);
3116
+ }
3117
+
2952
3118
 
2953
3119
  static void txn_finish(t_txnh *txn)
2954
3120
  {
2955
3121
  if ( RTEST(ruby_debug) )
2956
- rb_warning("%s/%d %s 0x%x",__FILE__,__LINE__,"txn_finish",txn);
3122
+ rb_warning("%s/%d %s 0x%p",__FILE__,__LINE__,"txn_finish",(void*)txn);
2957
3123
 
2958
3124
  txn->txn=NULL;
2959
3125
  if (txn->env) {
@@ -3116,6 +3282,9 @@ void Init_bdb() {
3116
3282
 
3117
3283
  cDb = rb_define_class_under(mBdb,"Db", rb_cObject);
3118
3284
  eDbError = rb_define_class_under(mBdb,"DbError",rb_eStandardError);
3285
+ #define eDbE_create(n,c) eDbE_##c = rb_define_class_under(mBdb, #c, eDbError);
3286
+ EXCEPTIONS_CREATE
3287
+
3119
3288
  rb_define_method(eDbError,"initialize",err_initialize,2);
3120
3289
  rb_define_method(eDbError,"code",err_code,0);
3121
3290
 
@@ -3135,6 +3304,8 @@ void Init_bdb() {
3135
3304
  rb_define_method(cDb,"cursor",db_cursor,2);
3136
3305
  rb_define_method(cDb,"associate",db_associate,4);
3137
3306
  rb_define_method(cDb,"btree_compare=",db_btree_compare_set,1);
3307
+ rb_define_method(cDb,"re_len=",db_set_re_len,1);
3308
+ rb_define_method(cDb,"re_len",db_get_re_len,0);
3138
3309
  rb_define_method(cDb,"flags=",db_flags_set,1);
3139
3310
  rb_define_method(cDb,"flags",db_flags_get,0);
3140
3311
  rb_define_method(cDb,"open",db_open,6);
@@ -3160,7 +3331,7 @@ void Init_bdb() {
3160
3331
  rb_define_method(cDb,"sync",db_sync,0);
3161
3332
  rb_define_method(cDb,"truncate",db_truncate,1);
3162
3333
 
3163
- #if DB_VERSION_MINOR > 3
3334
+ #if DB_VERSION_MAJOR == 5 || DB_VERSION_MINOR > 3
3164
3335
  rb_define_method(cDb,"compact",db_compact,5);
3165
3336
  #endif
3166
3337
 
@@ -3186,29 +3357,34 @@ void Init_bdb() {
3186
3357
  rb_define_method(cEnv,"txn_begin",env_txn_begin,2);
3187
3358
  rb_define_method(cEnv,"txn_checkpoint",env_txn_checkpoint,3);
3188
3359
  rb_define_method(cEnv,"txn_stat",env_txn_stat,1);
3189
- rb_define_method(cEnv,"set_timeout",env_set_timeout,2);
3190
- rb_define_method(cEnv,"get_timeout",env_get_timeout,1);
3191
- rb_define_method(cEnv,"set_tx_max",env_set_tx_max,1);
3360
+ rb_define_method(cEnv,"timeout",env_set_timeout,2);
3361
+ rb_define_method(cEnv,"timeout",env_get_timeout,1);
3192
3362
  rb_define_method(cEnv,"mutex_get_max",env_mutex_get_max,0);
3193
3363
  rb_define_method(cEnv,"mutex_set_max",env_mutex_set_max,1);
3194
- rb_define_method(cEnv,"get_tx_max",env_get_tx_max,0);
3364
+ rb_define_method(cEnv,"tx_max=",env_set_tx_max,1);
3365
+ rb_define_method(cEnv,"tx_max",env_get_tx_max,0);
3195
3366
  rb_define_method(cEnv,"report_stderr",env_report_stderr,0);
3196
- rb_define_method(cEnv,"set_lk_detect",env_set_lk_detect,1);
3197
- rb_define_method(cEnv,"get_lk_detect",env_get_lk_detect,0);
3198
- rb_define_method(cEnv,"set_lk_max_locks",env_set_lk_max_locks,1);
3199
- rb_define_method(cEnv,"get_lk_max_locks",env_get_lk_max_locks,0);
3200
- rb_define_method(cEnv,"set_lk_max_objects",env_set_lk_max_objects,1);
3201
- rb_define_method(cEnv,"get_lk_max_objects",env_get_lk_max_objects,0);
3202
- rb_define_method(cEnv,"set_shm_key",env_set_shm_key,1);
3203
- rb_define_method(cEnv,"get_shm_key",env_get_shm_key,0);
3204
-
3205
- rb_define_method(cEnv,"set_data_dir",env_set_data_dir,1);
3206
- rb_define_method(cEnv,"get_data_dirs",env_get_data_dirs,0);
3207
- rb_define_method(cEnv,"set_lg_dir",env_set_lg_dir,1);
3208
- rb_define_method(cEnv,"get_lg_dir",env_get_lg_dir,0);
3209
- rb_define_method(cEnv,"set_tmp_dir",env_set_tmp_dir,1);
3210
- rb_define_method(cEnv,"get_tmp_dir",env_get_tmp_dir,0);
3211
- rb_define_method(cEnv,"get_home",env_get_home,0);
3367
+ rb_define_method(cEnv,"lk_detect=",env_set_lk_detect,1);
3368
+ rb_define_method(cEnv,"lk_detect",env_get_lk_detect,0);
3369
+ rb_define_method(cEnv,"lk_max_locks=",env_set_lk_max_locks,1);
3370
+ rb_define_method(cEnv,"lk_max_locks",env_get_lk_max_locks,0);
3371
+ rb_define_method(cEnv,"lk_max_objects=",env_set_lk_max_objects,1);
3372
+ rb_define_method(cEnv,"lk_max_objects",env_get_lk_max_objects,0);
3373
+ rb_define_method(cEnv,"shm_key=",env_set_shm_key,1);
3374
+ rb_define_method(cEnv,"shm_key",env_get_shm_key,0);
3375
+ rb_define_method(cEnv,"log_config",env_log_set_config,2);
3376
+ #define ENV_LOG_CONFIG_FUNC(name,cnst) \
3377
+ rb_define_method(cEnv,"log_"#name "=",env_log_set_##cnst,1); \
3378
+ rb_define_method(cEnv,"log_"#name,env_log_get_##cnst,0);
3379
+ ENV_LOG_CONFIG_FUNCS
3380
+
3381
+ rb_define_method(cEnv,"data_dir=",env_set_data_dir,1);
3382
+ rb_define_method(cEnv,"data_dirs",env_get_data_dirs,0);
3383
+ rb_define_method(cEnv,"lg_dir=",env_set_lg_dir,1);
3384
+ rb_define_method(cEnv,"lg_dir",env_get_lg_dir,0);
3385
+ rb_define_method(cEnv,"tmp_dir=",env_set_tmp_dir,1);
3386
+ rb_define_method(cEnv,"tmp_dir",env_get_tmp_dir,0);
3387
+ rb_define_method(cEnv,"home",env_get_home,0);
3212
3388
  rb_define_method(cEnv,"set_verbose",env_set_verbose,2);
3213
3389
 
3214
3390
  rb_define_method(cEnv,"rep_priority=", env_rep_set_priority, 1);
@@ -3222,6 +3398,13 @@ void Init_bdb() {
3222
3398
  rb_define_method(cEnv,"repmgr_start", env_repmgr_start, 2);
3223
3399
  rb_define_method(cEnv,"repmgr_stat_print", env_repmgr_stat_print, 1);
3224
3400
 
3401
+ rb_define_method(cEnv,"lg_bsize=", env_set_lg_bsize, 1);
3402
+ rb_define_method(cEnv,"lg_bsize", env_get_lg_bsize, 0);
3403
+ rb_define_method(cEnv,"lg_max=", env_set_lg_max, 1);
3404
+ rb_define_method(cEnv,"lg_max", env_get_lg_max, 0);
3405
+ rb_define_method(cEnv,"lg_regionmax=", env_set_lg_regionmax, 1);
3406
+ rb_define_method(cEnv,"lg_regionmax", env_get_lg_regionmax, 0);
3407
+
3225
3408
  cTxnStat = rb_define_class_under(mBdb,"TxnStat",rb_cObject);
3226
3409
  rb_define_method(cTxnStat,"[]",stat_aref,1);
3227
3410
 
data/ext/bdb.h CHANGED
@@ -16,7 +16,7 @@
16
16
  #undef rename
17
17
  #endif
18
18
 
19
- #include <version.h>
19
+ //#include <version.h>
20
20
  #include <db.h>
21
21
 
22
22
  #define NOTXN NULL
@@ -1,11 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'mkmf'
3
- default_dir = '/usr/local/BerkeleyDB.4.8'
4
- inc, lib = dir_config('db', "#{default_dir}/include", "#{default_dir}/lib")
5
3
 
6
- versions=%w(db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
7
- until versions.empty?
8
- (lib_ok = have_library(versions.shift, 'db_version', 'db.h')) && break
4
+ # This list is checked in reverse order, so this order allows mkmf on my Mac
5
+ # to find BDB installed via Homebrew (/usr/local) before system installs
6
+ %w[/usr / /usr/local /usr/local/db* /usr/local/BerkeleyDB*].each do |pdir|
7
+ Dir[pdir].each do |dir|
8
+ dir_config('db', "#{dir}/include", "#{dir}/lib")
9
+ end
10
+ end
11
+
12
+ %w(db-5.1 db-5.0 db-4.9 db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2).each do |ver|
13
+ have_library ver, 'db_version', 'db.h'
9
14
  end
10
15
 
11
16
  def create_header
@@ -15,11 +20,12 @@ def create_header
15
20
  end
16
21
 
17
22
  message("Writing bdb_aux._c (defines), this takes a while\n")
23
+
18
24
  db_header = $CPPFLAGS.split.select { |f| f =~ /^-I/ }.map { |e|
19
25
  f = File.join(e[2..-1], 'db.h')
20
26
  File.exists?(f) ? f : nil
21
27
  }.select { |e| e }.first
22
-
28
+
23
29
  n=0
24
30
  defines=[]
25
31
  File.open(db_header) {|fd|
@@ -50,10 +56,10 @@ def create_header
50
56
  }
51
57
  end
52
58
 
53
- if lib_ok
59
+ #if lib_ok
54
60
  create_header
55
61
  create_makefile('bdb')
56
- else
57
- $stderr.puts("cannot create Makefile")
58
- exit 1
59
- end
62
+ #else
63
+ # $stderr.puts("cannot create Makefile")
64
+ # exit 1
65
+ #end
metadata CHANGED
@@ -1,32 +1,33 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bdb
3
- version: !ruby/object:Gem::Version
4
- version: 0.2.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.5
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Justin Balthrop
9
+ - Denis Knauf
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
-
12
- date: 2009-12-17 00:00:00 -08:00
13
- default_executable:
13
+ date: 2011-08-24 00:00:00.000000000Z
14
14
  dependencies: []
15
-
16
15
  description: Advanced Ruby Berkeley DB library.
17
- email: code@justinbalthrop.com
16
+ email:
17
+ - code@justinbalthrop.com
18
+ - Denis.Knauf@gmail.com
18
19
  executables: []
19
-
20
- extensions:
20
+ extensions:
21
21
  - ext/extconf.rb
22
- extra_rdoc_files:
22
+ extra_rdoc_files:
23
23
  - LICENSE
24
- - README.textile
25
- files:
24
+ - README.md
25
+ files:
26
+ - AUTHORS
27
+ - README.md
26
28
  - VERSION
27
29
  - ext/bdb.c
28
30
  - ext/bdb.h
29
- - ext/extconf.rb
30
31
  - lib/bdb/base.rb
31
32
  - lib/bdb/database.rb
32
33
  - lib/bdb/environment.rb
@@ -45,46 +46,30 @@ files:
45
46
  - test/test_helper.rb
46
47
  - test/txn_test.rb
47
48
  - LICENSE
48
- - README.textile
49
- has_rdoc: true
49
+ - ext/extconf.rb
50
50
  homepage: http://github.com/ninjudd/bdb
51
51
  licenses: []
52
-
53
52
  post_install_message:
54
- rdoc_options:
55
- - --charset=UTF-8
56
- require_paths:
53
+ rdoc_options: []
54
+ require_paths:
57
55
  - ext
58
56
  - lib
59
- required_ruby_version: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
64
- version:
65
- required_rubygems_version: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: "0"
70
- version:
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
71
69
  requirements: []
72
-
73
70
  rubyforge_project:
74
- rubygems_version: 1.3.5
71
+ rubygems_version: 1.8.9
75
72
  signing_key:
76
73
  specification_version: 3
77
74
  summary: Ruby Berkeley DB
78
- test_files:
79
- - test/benchmark.rb
80
- - test/cursor_test.rb
81
- - test/database_test.rb
82
- - test/database_test_helper.rb
83
- - test/db_test.rb
84
- - test/deadlock_test.rb
85
- - test/env_test.rb
86
- - test/replication_test.rb
87
- - test/stat_test.rb
88
- - test/test_helper.rb
89
- - test/txn_test.rb
90
- - examples/replication.rb
75
+ test_files: []
@@ -1,95 +0,0 @@
1
- h1. Bdb
2
-
3
- Ruby bindings for Berkeley DB versions 4.2-4.7.
4
-
5
- h2. Download
6
-
7
- Currently this library is available via git at:
8
-
9
- <pre>
10
- git://github.com/ninjudd/bdb.git
11
- </pre>
12
-
13
- h2. Installation
14
-
15
- h3. From Git
16
-
17
- You can check out the latest source from git:
18
-
19
- <pre>
20
- git clone git://github.com/ninjudd/bdb.git
21
- </pre>
22
-
23
- h3. As a Gem
24
-
25
- At the moment this library is not available on Rubyforge. To install it as a
26
- gem, do the following (for custom compiled version 4.8):
27
-
28
- <pre>
29
- sudo env ARCHFLAGS="-arch i386" gem install bdb --source http://gemcutter.org -- --with-db-dir=/usr/local/BerkeleyDB.4.8
30
- </pre>
31
-
32
- For Berkeley DB v4.7 installed from MacPorts do the following:
33
-
34
- <pre>
35
- sudo env ARCHFLAGS="-arch i386" gem install bdb --source http://gemcutter.org -- --with-db-include=/opt/local/include/db47 --with-db-lib=/opt/local/lib/db47
36
- </pre>
37
-
38
- This assumes you're on OS X and BerkeleyDB wasn't compiled as a universal binary.
39
-
40
- h2. Sample Usage
41
-
42
- <pre>
43
- env = Bdb::Env.new(0)
44
- env_flags = Bdb::DB_CREATE | # Create the environment if it does not already exist.
45
- Bdb::DB_INIT_TXN | # Initialize transactions
46
- Bdb::DB_INIT_LOCK | # Initialize locking.
47
- Bdb::DB_INIT_LOG | # Initialize logging
48
- Bdb::DB_INIT_MPOOL # Initialize the in-memory cache.
49
- env.open(File.join(File.dirname(__FILE__), 'tmp'), env_flags, 0);
50
-
51
- db = env.db
52
- db.open(nil, 'db1.db', nil, Bdb::Db::BTREE, Bdb::DB_CREATE | Bdb::DB_AUTO_COMMIT, 0)
53
-
54
- txn = env.txn_begin(nil, 0)
55
- db.put(txn, 'key', 'value', 0)
56
- txn.commit(0)
57
-
58
- value = db.get(nil, 'key', nil, 0)
59
-
60
- db.close(0)
61
- env.close
62
- </pre>
63
-
64
- h2. API
65
-
66
- This interface is most closely based on the DB4 C api and tries to maintain close
67
- interface proximity. That API is published by Oracle at "http://www.oracle.com/technology/documentation/berkeley-db/db/api_reference/C/frame_main.html":http://www.oracle.com/technology/documentation/berkeley-db/db/api_reference/C/frame_main.html.
68
-
69
- All function arguments systematically omit the leading DB handles and TXN handles.
70
- A few calls omit the flags parameter when the documentation indicates that no
71
- flag values are used - cursor.close is one.
72
-
73
- h2. Notes
74
-
75
- The defines generator is imperfect and includes some defines that are not
76
- flags. While it could be improved, it is easier to delete the incorrect ones.
77
- Thus, if you decide to rebuild the defines, you will need to edit the resulting
78
- file. This may be necessary if using a different release of DB4 than the ones
79
- the authors developed against. In nearly every case the defines generator works
80
- flawlessly.
81
-
82
- The authors have put all possible caution into ensuring that DB and Ruby cooperate.
83
- The memory access was one aspect carefully considered. Since Ruby copies
84
- when doing String#new, all key/data retrieval from DB is done with a 0 flag,
85
- meaning that DB will be responsible. See "this":http://groups.google.com/group/comp.databases.berkeley-db/browse_frm/thread/4f70a9999b64ce6a/c06b94692e3cbc41?tvc=1&q=dbt+malloc#c06b94692e3cbc41
86
- news group posting about the effect of that.
87
-
88
- The only other design consideration of consequence was associate. The prior
89
- version used a Ruby thread local variable and kept track of the current
90
- database in use. The authors decided to take a simpler approach since Ruby is green
91
- threads. A global array stores the VALUE of the Proc for a given association
92
- by the file descriptor number of the underlying database. This is looked
93
- up when the first layer callback is made. It would have been better considered
94
- if DB allowed the passing of a (void *) user data into the alloc that would
95
- be supplied during callback. So far this design has not produced any problems.
@@ -1,29 +0,0 @@
1
- require 'rubygems'
2
- require 'bdb/database'
3
- require 'fileutils'
4
-
5
- role = ARGV.shift || 'client'
6
-
7
- MASTER = 'localhost:8888'
8
- CLIENT = 'localhost:9999'
9
-
10
- DIR = "/tmp/#{role}"
11
- FileUtils.rmtree DIR
12
- FileUtils.mkdir DIR
13
-
14
- puts "Starting #{role}..."
15
-
16
- Bdb::Environment.replicate DIR, :from => MASTER, :to => CLIENT, :host => role == 'master' ? MASTER : CLIENT
17
- db = Bdb::Database.new('foo', :path => DIR)
18
-
19
- loop do
20
- 100.times do |i|
21
- if role == 'master'
22
- db.set(i, db[i].to_i + 1)
23
- puts "#{i}: #{db[i]}"
24
- else
25
- puts "#{i}: #{db[i]}"
26
- end
27
- sleep 0.1
28
- end
29
- end