… | |
… | |
31 | # include <unistd.h> |
31 | # include <unistd.h> |
32 | #endif |
32 | #endif |
33 | |
33 | |
34 | #include <db.h> |
34 | #include <db.h> |
35 | |
35 | |
36 | #if DB_VERSION_MAJOR != 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 3) |
36 | #define DBVER DB_VERSION_MAJOR * 100 + DB_VERSION_MINOR |
|
|
37 | |
|
|
38 | #if DBVER < 403 |
37 | # error you need Berkeley DB 4.3 or a newer 4.x version installed |
39 | # error you need Berkeley DB 4.3 or a newer version installed |
38 | #endif |
40 | #endif |
39 | |
41 | |
40 | /* number of seconds after which idle threads exit */ |
42 | /* number of seconds after which idle threads exit */ |
41 | #define IDLE_TIMEOUT 10 |
43 | #define IDLE_TIMEOUT 10 |
42 | |
44 | |
… | |
… | |
50 | typedef DB_ENV DB_ENV_ornuked; |
52 | typedef DB_ENV DB_ENV_ornuked; |
51 | typedef DB_TXN DB_TXN_ornuked; |
53 | typedef DB_TXN DB_TXN_ornuked; |
52 | typedef DBC DBC_ornuked; |
54 | typedef DBC DBC_ornuked; |
53 | typedef DB DB_ornuked; |
55 | typedef DB DB_ornuked; |
54 | |
56 | |
55 | #if DB_VERSION_MINOR >= 3 |
57 | #if DBVER >= 403 |
56 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
58 | typedef DB_SEQUENCE DB_SEQUENCE_ornull; |
57 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
59 | typedef DB_SEQUENCE DB_SEQUENCE_ornuked; |
58 | #endif |
60 | #endif |
59 | |
61 | |
60 | typedef char *bdb_filename; |
62 | typedef char *bdb_filename; |
… | |
… | |
67 | *bdb_txn_stash, |
69 | *bdb_txn_stash, |
68 | *bdb_cursor_stash, |
70 | *bdb_cursor_stash, |
69 | *bdb_db_stash, |
71 | *bdb_db_stash, |
70 | *bdb_sequence_stash; |
72 | *bdb_sequence_stash; |
71 | |
73 | |
72 | #if DB_VERSION_MINOR >= 6 |
74 | #if DBVER >= 406 |
73 | # define c_close close |
75 | # define c_close close |
74 | # define c_count count |
76 | # define c_count count |
75 | # define c_del del |
77 | # define c_del del |
76 | # define c_dup dup |
78 | # define c_dup dup |
77 | # define c_get get |
79 | # define c_get get |
… | |
… | |
186 | char *buf1, *buf2, *buf3; |
188 | char *buf1, *buf2, *buf3; |
187 | SV *sv1, *sv2, *sv3; |
189 | SV *sv1, *sv2, *sv3; |
188 | |
190 | |
189 | DBT dbt1, dbt2, dbt3; |
191 | DBT dbt1, dbt2, dbt3; |
190 | DB_KEY_RANGE key_range; |
192 | DB_KEY_RANGE key_range; |
191 | #if DB_VERSION_MINOR >= 3 |
193 | #if DBVER >= 403 |
192 | DB_SEQUENCE *seq; |
194 | DB_SEQUENCE *seq; |
193 | db_seq_t seq_t; |
195 | db_seq_t seq_t; |
194 | #endif |
196 | #endif |
195 | |
197 | |
196 | SV *rsv1, *rsv2; // keep some request objects alive |
198 | SV *rsv1, *rsv2; // keep some request objects alive |
… | |
… | |
397 | SvREFCNT_dec (av); |
399 | SvREFCNT_dec (av); |
398 | SvREFCNT_dec (req->sv1); |
400 | SvREFCNT_dec (req->sv1); |
399 | } |
401 | } |
400 | break; |
402 | break; |
401 | |
403 | |
402 | #if DB_VERSION_MINOR >= 3 |
404 | #if DBVER >= 403 |
403 | case REQ_SEQ_GET: |
405 | case REQ_SEQ_GET: |
404 | SvREADONLY_off (req->sv1); |
406 | SvREADONLY_off (req->sv1); |
405 | |
407 | |
406 | if (sizeof (IV) > 4) |
408 | if (sizeof (IV) > 4) |
407 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
409 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
… | |
… | |
749 | |
751 | |
750 | case REQ_DB_CLOSE: |
752 | case REQ_DB_CLOSE: |
751 | req->result = req->db->close (req->db, req->uint1); |
753 | req->result = req->db->close (req->db, req->uint1); |
752 | break; |
754 | break; |
753 | |
755 | |
754 | #if DB_VERSION_MINOR >= 4 |
756 | #if DBVER >= 404 |
755 | case REQ_DB_COMPACT: |
757 | case REQ_DB_COMPACT: |
756 | req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0); |
758 | req->result = req->db->compact (req->db, req->txn, req->dbt1.data ? &req->dbt1 : 0, req->dbt2.data ? &req->dbt2 : 0, 0, req->uint1, 0); |
757 | break; |
759 | break; |
758 | #endif |
760 | #endif |
759 | |
761 | |
… | |
… | |
771 | |
773 | |
772 | case REQ_DB_PUT: |
774 | case REQ_DB_PUT: |
773 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
775 | req->result = req->db->put (req->db, req->txn, &req->dbt1, &req->dbt2, req->uint1); |
774 | break; |
776 | break; |
775 | |
777 | |
776 | #if DB_VERSION_MINOR >= 6 |
778 | #if DBVER >= 406 |
777 | case REQ_DB_EXISTS: |
779 | case REQ_DB_EXISTS: |
778 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
780 | req->result = req->db->exists (req->db, req->txn, &req->dbt1, req->uint1); |
779 | break; |
781 | break; |
780 | #endif |
782 | #endif |
781 | case REQ_DB_GET: |
783 | case REQ_DB_GET: |
… | |
… | |
839 | |
841 | |
840 | case REQ_C_DEL: |
842 | case REQ_C_DEL: |
841 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
843 | req->result = req->dbc->c_del (req->dbc, req->uint1); |
842 | break; |
844 | break; |
843 | |
845 | |
844 | #if DB_VERSION_MINOR >= 3 |
846 | #if DBVER >= 403 |
845 | case REQ_SEQ_OPEN: |
847 | case REQ_SEQ_OPEN: |
846 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
848 | req->result = req->seq->open (req->seq, req->txn, &req->dbt1, req->uint1); |
847 | break; |
849 | break; |
848 | |
850 | |
849 | case REQ_SEQ_CLOSE: |
851 | case REQ_SEQ_CLOSE: |
… | |
… | |
1193 | static const struct { |
1195 | static const struct { |
1194 | const char *name; |
1196 | const char *name; |
1195 | IV iv; |
1197 | IV iv; |
1196 | } *civ, const_iv[] = { |
1198 | } *civ, const_iv[] = { |
1197 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
1199 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
|
|
1200 | #if DBVER <= 408 |
1198 | const_iv (RPCCLIENT) |
1201 | const_iv (RPCCLIENT) |
|
|
1202 | #endif |
1199 | const_iv (INIT_CDB) |
1203 | const_iv (INIT_CDB) |
1200 | const_iv (INIT_LOCK) |
1204 | const_iv (INIT_LOCK) |
1201 | const_iv (INIT_LOG) |
1205 | const_iv (INIT_LOG) |
1202 | const_iv (INIT_MPOOL) |
1206 | const_iv (INIT_MPOOL) |
1203 | const_iv (INIT_REP) |
1207 | const_iv (INIT_REP) |
… | |
… | |
1226 | const_iv (TXN_NOT_DURABLE) |
1230 | const_iv (TXN_NOT_DURABLE) |
1227 | const_iv (TXN_WRITE_NOSYNC) |
1231 | const_iv (TXN_WRITE_NOSYNC) |
1228 | const_iv (WRITECURSOR) |
1232 | const_iv (WRITECURSOR) |
1229 | const_iv (YIELDCPU) |
1233 | const_iv (YIELDCPU) |
1230 | const_iv (ENCRYPT_AES) |
1234 | const_iv (ENCRYPT_AES) |
1231 | #if DB_VERSION_MINOR < 8 |
1235 | #if DBVER < 408 |
1232 | const_iv (XA_CREATE) |
1236 | const_iv (XA_CREATE) |
1233 | #endif |
1237 | #endif |
1234 | const_iv (BTREE) |
1238 | const_iv (BTREE) |
1235 | const_iv (HASH) |
1239 | const_iv (HASH) |
1236 | const_iv (QUEUE) |
1240 | const_iv (QUEUE) |
… | |
… | |
1344 | const_iv (VERSION_MAJOR) |
1348 | const_iv (VERSION_MAJOR) |
1345 | const_iv (VERSION_MINOR) |
1349 | const_iv (VERSION_MINOR) |
1346 | const_iv (VERSION_PATCH) |
1350 | const_iv (VERSION_PATCH) |
1347 | const_iv (LOGVERSION) |
1351 | const_iv (LOGVERSION) |
1348 | const_iv (LOGOLDVER) |
1352 | const_iv (LOGOLDVER) |
1349 | #if DB_VERSION_MINOR >= 3 |
1353 | #if DBVER >= 403 |
1350 | const_iv (INORDER) |
1354 | const_iv (INORDER) |
1351 | const_iv (LOCK_MAXWRITE) |
1355 | const_iv (LOCK_MAXWRITE) |
1352 | const_iv (SEQ_DEC) |
1356 | const_iv (SEQ_DEC) |
1353 | const_iv (SEQ_INC) |
1357 | const_iv (SEQ_INC) |
1354 | const_iv (SEQ_WRAP) |
1358 | const_iv (SEQ_WRAP) |
1355 | const_iv (BUFFER_SMALL) |
1359 | const_iv (BUFFER_SMALL) |
1356 | const_iv (LOG_BUFFER_FULL) |
1360 | const_iv (LOG_BUFFER_FULL) |
1357 | const_iv (VERSION_MISMATCH) |
1361 | const_iv (VERSION_MISMATCH) |
1358 | #endif |
1362 | #endif |
1359 | #if DB_VERSION_MINOR >= 4 |
1363 | #if DBVER >= 404 |
1360 | const_iv (REGISTER) |
1364 | const_iv (REGISTER) |
1361 | const_iv (DSYNC_DB) |
1365 | const_iv (DSYNC_DB) |
1362 | const_iv (READ_COMMITTED) |
1366 | const_iv (READ_COMMITTED) |
1363 | const_iv (READ_UNCOMMITTED) |
1367 | const_iv (READ_UNCOMMITTED) |
1364 | const_iv (REP_IGNORE) |
1368 | const_iv (REP_IGNORE) |
… | |
… | |
1366 | const_iv (REP_JOIN_FAILURE) |
1370 | const_iv (REP_JOIN_FAILURE) |
1367 | const_iv (FREE_SPACE) |
1371 | const_iv (FREE_SPACE) |
1368 | const_iv (FREELIST_ONLY) |
1372 | const_iv (FREELIST_ONLY) |
1369 | const_iv (VERB_REGISTER) |
1373 | const_iv (VERB_REGISTER) |
1370 | #endif |
1374 | #endif |
1371 | #if DB_VERSION_MINOR >= 5 |
1375 | #if DBVER >= 405 |
1372 | const_iv (MULTIVERSION) |
1376 | const_iv (MULTIVERSION) |
1373 | const_iv (TXN_SNAPSHOT) |
1377 | const_iv (TXN_SNAPSHOT) |
1374 | #endif |
1378 | #endif |
1375 | #if DB_VERSION_MINOR >= 6 |
1379 | #if DBVER >= 406 |
1376 | const_iv (PREV_DUP) |
1380 | const_iv (PREV_DUP) |
1377 | const_iv (PRIORITY_UNCHANGED) |
1381 | const_iv (PRIORITY_UNCHANGED) |
1378 | const_iv (PRIORITY_VERY_LOW) |
1382 | const_iv (PRIORITY_VERY_LOW) |
1379 | const_iv (PRIORITY_LOW) |
1383 | const_iv (PRIORITY_LOW) |
1380 | const_iv (PRIORITY_DEFAULT) |
1384 | const_iv (PRIORITY_DEFAULT) |
1381 | const_iv (PRIORITY_HIGH) |
1385 | const_iv (PRIORITY_HIGH) |
1382 | const_iv (PRIORITY_VERY_HIGH) |
1386 | const_iv (PRIORITY_VERY_HIGH) |
1383 | const_iv (IGNORE_LEASE) |
1387 | const_iv (IGNORE_LEASE) |
1384 | #endif |
1388 | #endif |
1385 | #if DB_VERSION_MINOR >= 7 |
1389 | #if DBVER >= 407 |
1386 | //const_iv (MULTIPLE_KEY) |
1390 | //const_iv (MULTIPLE_KEY) |
1387 | const_iv (LOG_DIRECT) |
1391 | const_iv (LOG_DIRECT) |
1388 | const_iv (LOG_DSYNC) |
1392 | const_iv (LOG_DSYNC) |
1389 | const_iv (LOG_AUTO_REMOVE) |
1393 | const_iv (LOG_AUTO_REMOVE) |
1390 | const_iv (LOG_IN_MEMORY) |
1394 | const_iv (LOG_IN_MEMORY) |
1391 | const_iv (LOG_ZERO) |
1395 | const_iv (LOG_ZERO) |
1392 | #else |
1396 | #else |
1393 | const_iv (DIRECT_LOG) |
1397 | const_iv (DIRECT_LOG) |
1394 | const_iv (LOG_AUTOREMOVE) |
1398 | const_iv (LOG_AUTOREMOVE) |
1395 | # if DB_VERSION_MINOR >= 3 |
1399 | # if DBVER >= 403 |
1396 | const_iv (DSYNC_LOG) |
1400 | const_iv (DSYNC_LOG) |
1397 | const_iv (LOG_INMEMORY) |
1401 | const_iv (LOG_INMEMORY) |
1398 | # endif |
1402 | # endif |
1399 | #if DB_VERSION_MINOR >= 8 |
1403 | #if DBVER >= 408 |
1400 | const_iv (LOGVERSION_LATCHING) |
1404 | const_iv (LOGVERSION_LATCHING) |
1401 | #endif |
1405 | #endif |
1402 | #endif |
1406 | #endif |
1403 | }; |
1407 | }; |
1404 | |
1408 | |
… | |
… | |
1763 | req->uint1 = flags; |
1767 | req->uint1 = flags; |
1764 | req->sv1 = (SV *)db->app_private; |
1768 | req->sv1 = (SV *)db->app_private; |
1765 | REQ_SEND; |
1769 | REQ_SEND; |
1766 | } |
1770 | } |
1767 | |
1771 | |
1768 | #if DB_VERSION_MINOR >= 4 |
1772 | #if DBVER >= 404 |
1769 | |
1773 | |
1770 | void |
1774 | void |
1771 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1775 | db_compact (DB *db, DB_TXN_ornull *txn = 0, SV *start = 0, SV *stop = 0, SV *unused1 = 0, U32 flags = DB_FREE_SPACE, SV *unused2 = 0, SV *callback = 0) |
1772 | PREINIT: |
1776 | PREINIT: |
1773 | CALLBACK |
1777 | CALLBACK |
… | |
… | |
1852 | sv_to_dbt (&req->dbt2, data); |
1856 | sv_to_dbt (&req->dbt2, data); |
1853 | req->uint1 = flags; |
1857 | req->uint1 = flags; |
1854 | REQ_SEND; |
1858 | REQ_SEND; |
1855 | } |
1859 | } |
1856 | |
1860 | |
1857 | #if DB_VERSION_MINOR >= 6 |
1861 | #if DBVER >= 406 |
1858 | |
1862 | |
1859 | void |
1863 | void |
1860 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1864 | db_exists (DB *db, DB_TXN_ornull *txn, SV *key, U32 flags = 0, SV *callback = 0) |
1861 | PREINIT: |
1865 | PREINIT: |
1862 | CALLBACK |
1866 | CALLBACK |
… | |
… | |
2095 | req->uint1 = flags; |
2099 | req->uint1 = flags; |
2096 | REQ_SEND; |
2100 | REQ_SEND; |
2097 | } |
2101 | } |
2098 | |
2102 | |
2099 | |
2103 | |
2100 | #if DB_VERSION_MINOR >= 3 |
2104 | #if DBVER >= 403 |
2101 | |
2105 | |
2102 | void |
2106 | void |
2103 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2107 | db_sequence_open (DB_SEQUENCE *seq, DB_TXN_ornull *txnid, SV *key, U32 flags = 0, SV *callback = 0) |
2104 | PREINIT: |
2108 | PREINIT: |
2105 | CALLBACK |
2109 | CALLBACK |
… | |
… | |
2199 | CODE: |
2203 | CODE: |
2200 | RETVAL = env->set_flags (env, flags, onoff); |
2204 | RETVAL = env->set_flags (env, flags, onoff); |
2201 | OUTPUT: |
2205 | OUTPUT: |
2202 | RETVAL |
2206 | RETVAL |
2203 | |
2207 | |
2204 | #if DB_VERSION_MINOR >= 7 |
2208 | #if DBVER >= 407 |
2205 | |
2209 | |
2206 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2210 | int set_intermediate_dir_mode (DB_ENV *env, const char *mode) |
2207 | CODE: |
2211 | CODE: |
2208 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2212 | RETVAL = env->set_intermediate_dir_mode (env, mode); |
2209 | OUTPUT: |
2213 | OUTPUT: |
… | |
… | |
2296 | CODE: |
2300 | CODE: |
2297 | RETVAL = env->set_lg_max (env, max); |
2301 | RETVAL = env->set_lg_max (env, max); |
2298 | OUTPUT: |
2302 | OUTPUT: |
2299 | RETVAL |
2303 | RETVAL |
2300 | |
2304 | |
2301 | #if DB_VERSION_MINOR >= 4 |
2305 | #if DBVER >= 404 |
2302 | |
2306 | |
2303 | int mutex_set_max (DB_ENV *env, U32 max) |
2307 | int mutex_set_max (DB_ENV *env, U32 max) |
2304 | CODE: |
2308 | CODE: |
2305 | RETVAL = env->mutex_set_max (env, max); |
2309 | RETVAL = env->mutex_set_max (env, max); |
2306 | OUTPUT: |
2310 | OUTPUT: |
… | |
… | |
2333 | if (errno) |
2337 | if (errno) |
2334 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2338 | croak ("DB_ENV->txn_begin: %s", db_strerror (errno)); |
2335 | OUTPUT: |
2339 | OUTPUT: |
2336 | RETVAL |
2340 | RETVAL |
2337 | |
2341 | |
2338 | #if DB_VERSION_MINOR >= 5 |
2342 | #if DBVER >= 405 |
2339 | |
2343 | |
2340 | DB_TXN * |
2344 | DB_TXN * |
2341 | cdsgroup_begin (DB_ENV *env) |
2345 | cdsgroup_begin (DB_ENV *env) |
2342 | CODE: |
2346 | CODE: |
2343 | errno = env->cdsgroup_begin (env, &RETVAL); |
2347 | errno = env->cdsgroup_begin (env, &RETVAL); |
… | |
… | |
2445 | if (errno) |
2449 | if (errno) |
2446 | croak ("DB->cursor: %s", db_strerror (errno)); |
2450 | croak ("DB->cursor: %s", db_strerror (errno)); |
2447 | OUTPUT: |
2451 | OUTPUT: |
2448 | RETVAL |
2452 | RETVAL |
2449 | |
2453 | |
2450 | #if DB_VERSION_MINOR >= 3 |
2454 | #if DBVER >= 403 |
2451 | |
2455 | |
2452 | DB_SEQUENCE * |
2456 | DB_SEQUENCE * |
2453 | sequence (DB *db, U32 flags = 0) |
2457 | sequence (DB *db, U32 flags = 0) |
2454 | CODE: |
2458 | CODE: |
2455 | { |
2459 | { |
… | |
… | |
2490 | DESTROY (DBC_ornuked *dbc) |
2494 | DESTROY (DBC_ornuked *dbc) |
2491 | CODE: |
2495 | CODE: |
2492 | if (dbc) |
2496 | if (dbc) |
2493 | dbc->c_close (dbc); |
2497 | dbc->c_close (dbc); |
2494 | |
2498 | |
2495 | #if DB_VERSION_MINOR >= 6 |
2499 | #if DBVER >= 406 |
2496 | |
2500 | |
2497 | int set_priority (DBC *dbc, int priority) |
2501 | int set_priority (DBC *dbc, int priority) |
2498 | CODE: |
2502 | CODE: |
2499 | dbc->set_priority (dbc, priority); |
2503 | dbc->set_priority (dbc, priority); |
2500 | |
2504 | |
2501 | #endif |
2505 | #endif |
2502 | |
2506 | |
2503 | #if DB_VERSION_MINOR >= 3 |
2507 | #if DBVER >= 403 |
2504 | |
2508 | |
2505 | MODULE = BDB PACKAGE = BDB::Sequence |
2509 | MODULE = BDB PACKAGE = BDB::Sequence |
2506 | |
2510 | |
2507 | void |
2511 | void |
2508 | DESTROY (DB_SEQUENCE_ornuked *seq) |
2512 | DESTROY (DB_SEQUENCE_ornuked *seq) |