ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/BDB/BDB.xs
(Generate patch)

Comparing BDB/BDB.xs (file contents):
Revision 1.13 by root, Sun Jul 8 11:12:12 2007 UTC vs.
Revision 1.17 by root, Thu Sep 13 21:34:00 2007 UTC

45typedef SV SV8; /* byte-sv, used for argument-checking */ 45typedef SV SV8; /* byte-sv, used for argument-checking */
46typedef char *octetstring; 46typedef char *octetstring;
47 47
48static SV *prepare_cb; 48static SV *prepare_cb;
49 49
50#if DB_VERSION_MINOR >= 6
51# define c_close close
52# define c_count count
53# define c_del del
54# define c_dup dup
55# define c_get get
56# define c_pget pget
57# define c_put put
58#endif
59
60static void
61debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg)
62{
63 printf ("err[%s]\n", msg);
64}
65
66static void
67debug_msgcall (const DB_ENV *dbenv, const char *msg)
68{
69 printf ("msg[%s]\n", msg);
70}
71
50static char * 72static char *
51strdup_ornull (const char *s) 73strdup_ornull (const char *s)
52{ 74{
53 return s ? strdup (s) : 0; 75 return s ? strdup (s) : 0;
54} 76}
82 REQ_QUIT, 104 REQ_QUIT,
83 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, 105 REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT,
84 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, 106 REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE,
85 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, 107 REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC,
86 REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, 108 REQ_DB_PUT, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE,
87 REQ_TXN_COMMIT, REQ_TXN_ABORT, 109 REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH,
88 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, 110 REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL,
89 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, 111 REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE,
90}; 112};
91 113
92typedef struct aio_cb 114typedef struct aio_cb
646 X_UNLOCK (reqlock); 668 X_UNLOCK (reqlock);
647 669
648 switch (req->type) 670 switch (req->type)
649 { 671 {
650 case REQ_QUIT: 672 case REQ_QUIT:
673 req->result = ENOSYS;
651 goto quit; 674 goto quit;
652 675
653 case REQ_ENV_OPEN: 676 case REQ_ENV_OPEN:
654 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); 677 req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1);
655 break; 678 break;
714 req->result = req->txn->commit (req->txn, req->uint1); 737 req->result = req->txn->commit (req->txn, req->uint1);
715 break; 738 break;
716 739
717 case REQ_TXN_ABORT: 740 case REQ_TXN_ABORT:
718 req->result = req->txn->abort (req->txn); 741 req->result = req->txn->abort (req->txn);
742 break;
743
744 case REQ_TXN_FINISH:
745 if (req->txn->flags & TXN_DEADLOCK)
746 req->result = req->txn->commit (req->txn, req->uint1);
747 else
748 {
749 req->result = req->txn->abort (req->txn);
750 if (!req->result)
751 req->result = DB_LOCK_DEADLOCK;
752 }
719 break; 753 break;
720 754
721 case REQ_C_CLOSE: 755 case REQ_C_CLOSE:
722 req->result = req->dbc->c_close (req->dbc); 756 req->result = req->dbc->c_close (req->dbc);
723 break; 757 break;
764 798
765 default: 799 default:
766 req->result = ENOSYS; 800 req->result = ENOSYS;
767 break; 801 break;
768 } 802 }
803
804 if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED))
805 req->txn->flags |= TXN_DEADLOCK;
769 806
770 X_LOCK (reslock); 807 X_LOCK (reslock);
771 808
772 ++npending; 809 ++npending;
773 810
1018 const_iv (LOCK_YOUNGEST) 1055 const_iv (LOCK_YOUNGEST)
1019 1056
1020 const_iv (SEQ_DEC) 1057 const_iv (SEQ_DEC)
1021 const_iv (SEQ_INC) 1058 const_iv (SEQ_INC)
1022 const_iv (SEQ_WRAP) 1059 const_iv (SEQ_WRAP)
1060
1061 const_iv (BUFFER_SMALL)
1062 const_iv (DONOTINDEX)
1063 const_iv (KEYEMPTY )
1064 const_iv (KEYEXIST )
1065 const_iv (LOCK_DEADLOCK)
1066 const_iv (LOCK_NOTGRANTED)
1067 const_iv (LOG_BUFFER_FULL)
1068 const_iv (NOSERVER)
1069 const_iv (NOSERVER_HOME)
1070 const_iv (NOSERVER_ID)
1071 const_iv (NOTFOUND)
1072 const_iv (OLD_VERSION)
1073 const_iv (PAGE_NOTFOUND)
1074 const_iv (REP_DUPMASTER)
1075 const_iv (REP_HANDLE_DEAD)
1076 const_iv (REP_HOLDELECTION)
1077 const_iv (REP_IGNORE)
1078 const_iv (REP_ISPERM)
1079 const_iv (REP_JOIN_FAILURE)
1080 const_iv (REP_LOCKOUT)
1081 const_iv (REP_NEWMASTER)
1082 const_iv (REP_NEWSITE)
1083 const_iv (REP_NOTPERM)
1084 const_iv (REP_UNAVAIL)
1085 const_iv (RUNRECOVERY)
1086 const_iv (SECONDARY_BAD)
1087 const_iv (VERIFY_BAD)
1088 const_iv (VERSION_MISMATCH)
1089
1090 const_iv (VERB_DEADLOCK)
1091 const_iv (VERB_RECOVERY)
1092 const_iv (VERB_REGISTER)
1093 const_iv (VERB_REPLICATION)
1094 const_iv (VERB_WAITSFOR)
1095
1096 const_iv (VERSION_MAJOR)
1097 const_iv (VERSION_MINOR)
1098 const_iv (VERSION_PATCH)
1023#if DB_VERSION_MINOR >= 5 1099#if DB_VERSION_MINOR >= 5
1024 const_iv (MULTIVERSION) 1100 const_iv (MULTIVERSION)
1025 const_iv (TXN_SNAPSHOT) 1101 const_iv (TXN_SNAPSHOT)
1026#endif 1102#endif
1103#if DB_VERSION_MINOR >= 6
1104 const_iv (PREV_DUP)
1105# if 0
1106 const_iv (PRIORITY_UNCHANGED)
1107 const_iv (PRIORITY_VERY_LOW)
1108 const_iv (PRIORITY_LOW)
1109 const_iv (PRIORITY_DEFAULT)
1110 const_iv (PRIORITY_HIGH)
1111 const_iv (PRIORITY_VERY_HIGH)
1112# endif
1113#endif
1027 }; 1114 };
1028 1115
1029 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1116 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1030 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1117 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1118
1119 newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1));
1120 newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0));
1031 1121
1032 create_pipe (respipe); 1122 create_pipe (respipe);
1033 1123
1034 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); 1124 X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child);
1035#ifdef _WIN32 1125#ifdef _WIN32
1178 PROTOTYPE: & 1268 PROTOTYPE: &
1179 CODE: 1269 CODE:
1180 SvREFCNT_dec (prepare_cb); 1270 SvREFCNT_dec (prepare_cb);
1181 prepare_cb = newSVsv (cb); 1271 prepare_cb = newSVsv (cb);
1182 1272
1273char *
1274strerror (int errorno = errno)
1275 PROTOTYPE: ;$
1276 CODE:
1277 RETVAL = db_strerror (errorno);
1278 OUTPUT:
1279 RETVAL
1183 1280
1184DB_ENV * 1281DB_ENV *
1185db_env_create (U32 env_flags = 0) 1282db_env_create (U32 env_flags = 0)
1186 CODE: 1283 CODE:
1187{ 1284{
1188 errno = db_env_create (&RETVAL, env_flags); 1285 errno = db_env_create (&RETVAL, env_flags);
1189 if (errno) 1286 if (errno)
1190 croak ("db_env_create: %s", db_strerror (errno)); 1287 croak ("db_env_create: %s", db_strerror (errno));
1288
1289 if (0)
1290 {
1291 RETVAL->set_errcall (RETVAL, debug_errcall);
1292 RETVAL->set_msgcall (RETVAL, debug_msgcall);
1293 }
1191} 1294}
1192 OUTPUT: 1295 OUTPUT:
1193 RETVAL 1296 RETVAL
1194 1297
1195void 1298void
1196db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef) 1299db_env_open (DB_ENV *env, octetstring db_home, U32 open_flags, int mode, SV *callback = &PL_sv_undef)
1197 CODE: 1300 CODE:
1198{ 1301{
1199 dREQ (REQ_ENV_OPEN); 1302 dREQ (REQ_ENV_OPEN);
1200 1303
1201 env->set_thread_count (env, get_nthreads ()); 1304 env->set_thread_count (env, wanted + 2);
1202 1305
1203 req->env = env; 1306 req->env = env;
1204 req->uint1 = open_flags | DB_THREAD; 1307 req->uint1 = open_flags | DB_THREAD;
1205 req->int1 = mode; 1308 req->int1 = mode;
1206 req->buf1 = strdup_ornull (db_home); 1309 req->buf1 = strdup_ornull (db_home);
1412 REQ_SEND; 1515 REQ_SEND;
1413 ptr_nuke (ST (0)); 1516 ptr_nuke (ST (0));
1414} 1517}
1415 1518
1416void 1519void
1520db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef)
1521 CODE:
1522{
1523 dREQ (REQ_TXN_FINISH);
1524 req->txn = txn;
1525 req->uint1 = flags;
1526 REQ_SEND;
1527 ptr_nuke (ST (0));
1528}
1529
1530void
1417db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) 1531db_c_close (DBC *dbc, SV *callback = &PL_sv_undef)
1418 CODE: 1532 CODE:
1419{ 1533{
1420 dREQ (REQ_C_CLOSE); 1534 dREQ (REQ_C_CLOSE);
1421 req->dbc = dbc; 1535 req->dbc = dbc;
1599 CODE: 1713 CODE:
1600 RETVAL = env->set_flags (env, flags, onoff); 1714 RETVAL = env->set_flags (env, flags, onoff);
1601 OUTPUT: 1715 OUTPUT:
1602 RETVAL 1716 RETVAL
1603 1717
1718void set_errfile (DB_ENV *env, FILE *errfile = 0)
1719 CODE:
1720 env->set_errfile (env, errfile);
1721
1722void set_msgfile (DB_ENV *env, FILE *msgfile = 0)
1723 CODE:
1724 env->set_msgfile (env, msgfile);
1725
1726int set_verbose (DB_ENV *env, U32 which, int onoff = 1)
1727 CODE:
1728 RETVAL = env->set_verbose (env, which, onoff);
1729 OUTPUT:
1730 RETVAL
1731
1604int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0) 1732int set_encrypt (DB_ENV *env, const char *password, U32 flags = 0)
1605 CODE: 1733 CODE:
1606 RETVAL = env->set_encrypt (env, password, flags); 1734 RETVAL = env->set_encrypt (env, password, flags);
1607 OUTPUT: 1735 OUTPUT:
1608 RETVAL 1736 RETVAL
1609 1737
1610int set_timeout (DB_ENV *env, NV timeout, U32 flags) 1738int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1611 CODE: 1739 CODE:
1612 RETVAL = env->set_timeout (env, timeout * 1000000, flags); 1740 RETVAL = env->set_timeout (env, timeout * 1000000, flags);
1613 OUTPUT: 1741 OUTPUT:
1614 RETVAL 1742 RETVAL
1615 1743
1692 CODE: 1820 CODE:
1693 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); 1821 RETVAL = db->set_cachesize (db, gbytes, bytes, ncache);
1694 OUTPUT: 1822 OUTPUT:
1695 RETVAL 1823 RETVAL
1696 1824
1697int set_flags (DB *db, U32 flags); 1825int set_flags (DB *db, U32 flags)
1698 CODE: 1826 CODE:
1699 RETVAL = db->set_flags (db, flags); 1827 RETVAL = db->set_flags (db, flags);
1700 OUTPUT: 1828 OUTPUT:
1701 RETVAL 1829 RETVAL
1702 1830
1716 CODE: 1844 CODE:
1717 RETVAL = db->set_bt_minkey (db, minkey); 1845 RETVAL = db->set_bt_minkey (db, minkey);
1718 OUTPUT: 1846 OUTPUT:
1719 RETVAL 1847 RETVAL
1720 1848
1721int set_re_delim(DB *db, int delim); 1849int set_re_delim (DB *db, int delim)
1722 CODE: 1850 CODE:
1723 RETVAL = db->set_re_delim (db, delim); 1851 RETVAL = db->set_re_delim (db, delim);
1724 OUTPUT: 1852 OUTPUT:
1725 RETVAL 1853 RETVAL
1726 1854
1787DESTROY (DB_TXN_ornull *txn) 1915DESTROY (DB_TXN_ornull *txn)
1788 CODE: 1916 CODE:
1789 if (txn) 1917 if (txn)
1790 txn->abort (txn); 1918 txn->abort (txn);
1791 1919
1792int set_timeout (DB_TXN *txn, NV timeout, U32 flags) 1920int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT)
1793 CODE: 1921 CODE:
1794 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); 1922 RETVAL = txn->set_timeout (txn, timeout * 1000000, flags);
1923 OUTPUT:
1924 RETVAL
1925
1926int failed (DB_TXN *txn)
1927 CODE:
1928 RETVAL = !!(txn->flags & TXN_DEADLOCK);
1795 OUTPUT: 1929 OUTPUT:
1796 RETVAL 1930 RETVAL
1797 1931
1798 1932
1799MODULE = BDB PACKAGE = BDB::Cursor 1933MODULE = BDB PACKAGE = BDB::Cursor

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines