… | |
… | |
45 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
45 | typedef SV SV8; /* byte-sv, used for argument-checking */ |
46 | typedef char *octetstring; |
46 | typedef char *octetstring; |
47 | |
47 | |
48 | static SV *prepare_cb; |
48 | static 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 | |
50 | static void |
60 | static void |
51 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
61 | debug_errcall (const DB_ENV *dbenv, const char *errpfx, const char *msg) |
52 | { |
62 | { |
53 | printf ("err[%s]\n", msg); |
63 | printf ("err[%s]\n", msg); |
54 | } |
64 | } |
… | |
… | |
94 | REQ_QUIT, |
104 | REQ_QUIT, |
95 | 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, |
96 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
106 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, |
97 | 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, |
98 | 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, |
99 | REQ_TXN_COMMIT, REQ_TXN_ABORT, |
109 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
100 | 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, |
101 | 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, |
102 | }; |
112 | }; |
103 | |
113 | |
104 | typedef struct aio_cb |
114 | typedef struct aio_cb |
… | |
… | |
181 | } |
191 | } |
182 | |
192 | |
183 | static volatile unsigned int nreqs, nready, npending; |
193 | static volatile unsigned int nreqs, nready, npending; |
184 | static volatile unsigned int max_idle = 4; |
194 | static volatile unsigned int max_idle = 4; |
185 | static volatile unsigned int max_outstanding = 0xffffffff; |
195 | static volatile unsigned int max_outstanding = 0xffffffff; |
186 | static int respipe [2], respipe_osf [2]; |
196 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
187 | |
197 | |
188 | static mutex_t reslock = X_MUTEX_INIT; |
198 | static mutex_t reslock = X_MUTEX_INIT; |
189 | static mutex_t reqlock = X_MUTEX_INIT; |
199 | static mutex_t reqlock = X_MUTEX_INIT; |
190 | static cond_t reqwait = X_COND_INIT; |
200 | static cond_t reqwait = X_COND_INIT; |
191 | |
201 | |
… | |
… | |
334 | |
344 | |
335 | case REQ_SEQ_GET: |
345 | case REQ_SEQ_GET: |
336 | SvREADONLY_off (req->sv1); |
346 | SvREADONLY_off (req->sv1); |
337 | |
347 | |
338 | if (sizeof (IV) > 4) |
348 | if (sizeof (IV) > 4) |
339 | sv_setiv_mg (req->sv1, req->seq_t); |
349 | sv_setiv_mg (req->sv1, (IV)req->seq_t); |
340 | else |
350 | else |
341 | sv_setnv_mg (req->sv1, req->seq_t); |
351 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
342 | |
352 | |
343 | SvREFCNT_dec (req->sv1); |
353 | SvREFCNT_dec (req->sv1); |
344 | break; |
354 | break; |
345 | } |
355 | } |
346 | |
356 | |
… | |
… | |
369 | #else |
379 | #else |
370 | # define TO_SOCKET(x) (x) |
380 | # define TO_SOCKET(x) (x) |
371 | #endif |
381 | #endif |
372 | |
382 | |
373 | static void |
383 | static void |
374 | create_pipe (int fd[2]) |
384 | create_respipe () |
375 | { |
385 | { |
376 | #ifdef _WIN32 |
386 | #ifdef _WIN32 |
377 | int arg = 1; |
387 | int arg; /* argg */ |
|
|
388 | #endif |
|
|
389 | int old_readfd = respipe [0]; |
|
|
390 | |
|
|
391 | if (respipe [1] >= 0) |
|
|
392 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
393 | |
|
|
394 | #ifdef _WIN32 |
378 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, fd) |
395 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
379 | || ioctlsocket (TO_SOCKET (fd [0]), FIONBIO, &arg) |
|
|
380 | || ioctlsocket (TO_SOCKET (fd [1]), FIONBIO, &arg)) |
|
|
381 | #else |
396 | #else |
382 | if (pipe (fd) |
397 | if (pipe (respipe)) |
383 | || fcntl (fd [0], F_SETFL, O_NONBLOCK) |
|
|
384 | || fcntl (fd [1], F_SETFL, O_NONBLOCK)) |
|
|
385 | #endif |
398 | #endif |
386 | croak ("unable to initialize result pipe"); |
399 | croak ("unable to initialize result pipe"); |
|
|
400 | |
|
|
401 | if (old_readfd >= 0) |
|
|
402 | { |
|
|
403 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
404 | croak ("unable to initialize result pipe(2)"); |
|
|
405 | |
|
|
406 | respipe_close (respipe [0]); |
|
|
407 | respipe [0] = old_readfd; |
|
|
408 | } |
|
|
409 | |
|
|
410 | #ifdef _WIN32 |
|
|
411 | arg = 1; |
|
|
412 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
413 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
414 | #else |
|
|
415 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
416 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
417 | #endif |
|
|
418 | croak ("unable to initialize result pipe(3)"); |
387 | |
419 | |
388 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
420 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
389 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
421 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
390 | } |
422 | } |
391 | |
423 | |
… | |
… | |
658 | X_UNLOCK (reqlock); |
690 | X_UNLOCK (reqlock); |
659 | |
691 | |
660 | switch (req->type) |
692 | switch (req->type) |
661 | { |
693 | { |
662 | case REQ_QUIT: |
694 | case REQ_QUIT: |
|
|
695 | req->result = ENOSYS; |
663 | goto quit; |
696 | goto quit; |
664 | |
697 | |
665 | case REQ_ENV_OPEN: |
698 | case REQ_ENV_OPEN: |
666 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
699 | req->result = req->env->open (req->env, req->buf1, req->uint1, req->int1); |
667 | break; |
700 | break; |
… | |
… | |
726 | req->result = req->txn->commit (req->txn, req->uint1); |
759 | req->result = req->txn->commit (req->txn, req->uint1); |
727 | break; |
760 | break; |
728 | |
761 | |
729 | case REQ_TXN_ABORT: |
762 | case REQ_TXN_ABORT: |
730 | req->result = req->txn->abort (req->txn); |
763 | req->result = req->txn->abort (req->txn); |
|
|
764 | break; |
|
|
765 | |
|
|
766 | case REQ_TXN_FINISH: |
|
|
767 | if (req->txn->flags & TXN_DEADLOCK) |
|
|
768 | { |
|
|
769 | req->result = req->txn->abort (req->txn); |
|
|
770 | if (!req->result) |
|
|
771 | req->result = DB_LOCK_DEADLOCK; |
|
|
772 | } |
|
|
773 | else |
|
|
774 | req->result = req->txn->commit (req->txn, req->uint1); |
731 | break; |
775 | break; |
732 | |
776 | |
733 | case REQ_C_CLOSE: |
777 | case REQ_C_CLOSE: |
734 | req->result = req->dbc->c_close (req->dbc); |
778 | req->result = req->dbc->c_close (req->dbc); |
735 | break; |
779 | break; |
… | |
… | |
777 | default: |
821 | default: |
778 | req->result = ENOSYS; |
822 | req->result = ENOSYS; |
779 | break; |
823 | break; |
780 | } |
824 | } |
781 | |
825 | |
|
|
826 | if (req->txn && (req->result > 0 || req->result == DB_LOCK_NOTGRANTED)) |
|
|
827 | req->txn->flags |= TXN_DEADLOCK; |
|
|
828 | |
782 | X_LOCK (reslock); |
829 | X_LOCK (reslock); |
783 | |
830 | |
784 | ++npending; |
831 | ++npending; |
785 | |
832 | |
786 | if (!reqq_push (&res_queue, req)) |
833 | if (!reqq_push (&res_queue, req)) |
… | |
… | |
842 | idle = 0; |
889 | idle = 0; |
843 | nreqs = 0; |
890 | nreqs = 0; |
844 | nready = 0; |
891 | nready = 0; |
845 | npending = 0; |
892 | npending = 0; |
846 | |
893 | |
847 | respipe_close (respipe [0]); |
|
|
848 | respipe_close (respipe [1]); |
|
|
849 | |
|
|
850 | create_pipe (respipe); |
894 | create_respipe (); |
851 | |
895 | |
852 | atfork_parent (); |
896 | atfork_parent (); |
853 | } |
897 | } |
854 | |
898 | |
855 | #define dREQ(reqtype) \ |
899 | #define dREQ(reqtype) \ |
… | |
… | |
919 | const_iv (INIT_TXN) |
963 | const_iv (INIT_TXN) |
920 | const_iv (RECOVER) |
964 | const_iv (RECOVER) |
921 | const_iv (INIT_TXN) |
965 | const_iv (INIT_TXN) |
922 | const_iv (RECOVER_FATAL) |
966 | const_iv (RECOVER_FATAL) |
923 | const_iv (CREATE) |
967 | const_iv (CREATE) |
|
|
968 | const_iv (RDONLY) |
924 | const_iv (USE_ENVIRON) |
969 | const_iv (USE_ENVIRON) |
925 | const_iv (USE_ENVIRON_ROOT) |
970 | const_iv (USE_ENVIRON_ROOT) |
926 | const_iv (LOCKDOWN) |
971 | const_iv (LOCKDOWN) |
927 | const_iv (PRIVATE) |
972 | const_iv (PRIVATE) |
928 | const_iv (REGISTER) |
973 | const_iv (REGISTER) |
… | |
… | |
941 | const_iv (OVERWRITE) |
986 | const_iv (OVERWRITE) |
942 | const_iv (PANIC_ENVIRONMENT) |
987 | const_iv (PANIC_ENVIRONMENT) |
943 | const_iv (REGION_INIT) |
988 | const_iv (REGION_INIT) |
944 | const_iv (TIME_NOTGRANTED) |
989 | const_iv (TIME_NOTGRANTED) |
945 | const_iv (TXN_NOSYNC) |
990 | const_iv (TXN_NOSYNC) |
|
|
991 | const_iv (TXN_NOT_DURABLE) |
946 | const_iv (TXN_WRITE_NOSYNC) |
992 | const_iv (TXN_WRITE_NOSYNC) |
947 | const_iv (WRITECURSOR) |
993 | const_iv (WRITECURSOR) |
948 | const_iv (YIELDCPU) |
994 | const_iv (YIELDCPU) |
949 | const_iv (ENCRYPT_AES) |
995 | const_iv (ENCRYPT_AES) |
950 | const_iv (XA_CREATE) |
996 | const_iv (XA_CREATE) |
… | |
… | |
958 | const_iv (READ_UNCOMMITTED) |
1004 | const_iv (READ_UNCOMMITTED) |
959 | const_iv (TRUNCATE) |
1005 | const_iv (TRUNCATE) |
960 | const_iv (NOSYNC) |
1006 | const_iv (NOSYNC) |
961 | const_iv (CHKSUM) |
1007 | const_iv (CHKSUM) |
962 | const_iv (ENCRYPT) |
1008 | const_iv (ENCRYPT) |
963 | const_iv (TXN_NOT_DURABLE) |
|
|
964 | const_iv (DUP) |
1009 | const_iv (DUP) |
965 | const_iv (DUPSORT) |
1010 | const_iv (DUPSORT) |
966 | const_iv (RECNUM) |
1011 | const_iv (RECNUM) |
967 | const_iv (RENUMBER) |
1012 | const_iv (RENUMBER) |
968 | const_iv (REVSPLITOFF) |
1013 | const_iv (REVSPLITOFF) |
… | |
… | |
1073 | const_iv (VERSION_PATCH) |
1118 | const_iv (VERSION_PATCH) |
1074 | #if DB_VERSION_MINOR >= 5 |
1119 | #if DB_VERSION_MINOR >= 5 |
1075 | const_iv (MULTIVERSION) |
1120 | const_iv (MULTIVERSION) |
1076 | const_iv (TXN_SNAPSHOT) |
1121 | const_iv (TXN_SNAPSHOT) |
1077 | #endif |
1122 | #endif |
|
|
1123 | #if DB_VERSION_MINOR >= 6 |
|
|
1124 | const_iv (PREV_DUP) |
|
|
1125 | # if 0 |
|
|
1126 | const_iv (PRIORITY_UNCHANGED) |
|
|
1127 | const_iv (PRIORITY_VERY_LOW) |
|
|
1128 | const_iv (PRIORITY_LOW) |
|
|
1129 | const_iv (PRIORITY_DEFAULT) |
|
|
1130 | const_iv (PRIORITY_HIGH) |
|
|
1131 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1132 | # endif |
|
|
1133 | #endif |
1078 | }; |
1134 | }; |
1079 | |
1135 | |
1080 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1136 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1081 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1137 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1082 | |
1138 | |
1083 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1139 | newCONSTSUB (stash, "DB_VERSION", newSVnv (DB_VERSION_MAJOR + DB_VERSION_MINOR * .1)); |
1084 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1140 | newCONSTSUB (stash, "DB_VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1085 | |
1141 | |
1086 | create_pipe (respipe); |
1142 | create_respipe (); |
1087 | |
1143 | |
1088 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1144 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1089 | #ifdef _WIN32 |
1145 | #ifdef _WIN32 |
1090 | X_MUTEX_CHECK (wrklock); |
1146 | X_MUTEX_CHECK (wrklock); |
1091 | X_MUTEX_CHECK (reslock); |
1147 | X_MUTEX_CHECK (reslock); |
… | |
… | |
1479 | REQ_SEND; |
1535 | REQ_SEND; |
1480 | ptr_nuke (ST (0)); |
1536 | ptr_nuke (ST (0)); |
1481 | } |
1537 | } |
1482 | |
1538 | |
1483 | void |
1539 | void |
|
|
1540 | db_txn_finish (DB_TXN *txn, U32 flags = 0, SV *callback = &PL_sv_undef) |
|
|
1541 | CODE: |
|
|
1542 | { |
|
|
1543 | dREQ (REQ_TXN_FINISH); |
|
|
1544 | req->txn = txn; |
|
|
1545 | req->uint1 = flags; |
|
|
1546 | REQ_SEND; |
|
|
1547 | ptr_nuke (ST (0)); |
|
|
1548 | } |
|
|
1549 | |
|
|
1550 | void |
1484 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1551 | db_c_close (DBC *dbc, SV *callback = &PL_sv_undef) |
1485 | CODE: |
1552 | CODE: |
1486 | { |
1553 | { |
1487 | dREQ (REQ_C_CLOSE); |
1554 | dREQ (REQ_C_CLOSE); |
1488 | req->dbc = dbc; |
1555 | req->dbc = dbc; |
… | |
… | |
1666 | CODE: |
1733 | CODE: |
1667 | RETVAL = env->set_flags (env, flags, onoff); |
1734 | RETVAL = env->set_flags (env, flags, onoff); |
1668 | OUTPUT: |
1735 | OUTPUT: |
1669 | RETVAL |
1736 | RETVAL |
1670 | |
1737 | |
1671 | void set_errfile (DB_ENV *env, FILE *errfile) |
1738 | void set_errfile (DB_ENV *env, FILE *errfile = 0) |
1672 | CODE: |
1739 | CODE: |
1673 | env->set_errfile (env, errfile); |
1740 | env->set_errfile (env, errfile); |
1674 | |
1741 | |
1675 | void set_msgfile (DB_ENV *env, FILE *msgfile) |
1742 | void set_msgfile (DB_ENV *env, FILE *msgfile = 0) |
1676 | CODE: |
1743 | CODE: |
1677 | env->set_msgfile (env, msgfile); |
1744 | env->set_msgfile (env, msgfile); |
1678 | |
1745 | |
1679 | int set_verbose (DB_ENV *env, U32 which, int onoff = 1) |
1746 | int set_verbose (DB_ENV *env, U32 which, int onoff = 1) |
1680 | CODE: |
1747 | CODE: |
… | |
… | |
1686 | CODE: |
1753 | CODE: |
1687 | RETVAL = env->set_encrypt (env, password, flags); |
1754 | RETVAL = env->set_encrypt (env, password, flags); |
1688 | OUTPUT: |
1755 | OUTPUT: |
1689 | RETVAL |
1756 | RETVAL |
1690 | |
1757 | |
1691 | int set_timeout (DB_ENV *env, NV timeout, U32 flags) |
1758 | int set_timeout (DB_ENV *env, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1692 | CODE: |
1759 | CODE: |
1693 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1760 | RETVAL = env->set_timeout (env, timeout * 1000000, flags); |
1694 | OUTPUT: |
1761 | OUTPUT: |
1695 | RETVAL |
1762 | RETVAL |
1696 | |
1763 | |
… | |
… | |
1773 | CODE: |
1840 | CODE: |
1774 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1841 | RETVAL = db->set_cachesize (db, gbytes, bytes, ncache); |
1775 | OUTPUT: |
1842 | OUTPUT: |
1776 | RETVAL |
1843 | RETVAL |
1777 | |
1844 | |
1778 | int set_flags (DB *db, U32 flags); |
1845 | int set_flags (DB *db, U32 flags) |
1779 | CODE: |
1846 | CODE: |
1780 | RETVAL = db->set_flags (db, flags); |
1847 | RETVAL = db->set_flags (db, flags); |
1781 | OUTPUT: |
1848 | OUTPUT: |
1782 | RETVAL |
1849 | RETVAL |
1783 | |
1850 | |
… | |
… | |
1797 | CODE: |
1864 | CODE: |
1798 | RETVAL = db->set_bt_minkey (db, minkey); |
1865 | RETVAL = db->set_bt_minkey (db, minkey); |
1799 | OUTPUT: |
1866 | OUTPUT: |
1800 | RETVAL |
1867 | RETVAL |
1801 | |
1868 | |
1802 | int set_re_delim(DB *db, int delim); |
1869 | int set_re_delim (DB *db, int delim) |
1803 | CODE: |
1870 | CODE: |
1804 | RETVAL = db->set_re_delim (db, delim); |
1871 | RETVAL = db->set_re_delim (db, delim); |
1805 | OUTPUT: |
1872 | OUTPUT: |
1806 | RETVAL |
1873 | RETVAL |
1807 | |
1874 | |
… | |
… | |
1868 | DESTROY (DB_TXN_ornull *txn) |
1935 | DESTROY (DB_TXN_ornull *txn) |
1869 | CODE: |
1936 | CODE: |
1870 | if (txn) |
1937 | if (txn) |
1871 | txn->abort (txn); |
1938 | txn->abort (txn); |
1872 | |
1939 | |
1873 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags) |
1940 | int set_timeout (DB_TXN *txn, NV timeout, U32 flags = DB_SET_TXN_TIMEOUT) |
1874 | CODE: |
1941 | CODE: |
1875 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
1942 | RETVAL = txn->set_timeout (txn, timeout * 1000000, flags); |
|
|
1943 | OUTPUT: |
|
|
1944 | RETVAL |
|
|
1945 | |
|
|
1946 | int failed (DB_TXN *txn) |
|
|
1947 | CODE: |
|
|
1948 | RETVAL = !!(txn->flags & TXN_DEADLOCK); |
1876 | OUTPUT: |
1949 | OUTPUT: |
1877 | RETVAL |
1950 | RETVAL |
1878 | |
1951 | |
1879 | |
1952 | |
1880 | MODULE = BDB PACKAGE = BDB::Cursor |
1953 | MODULE = BDB PACKAGE = BDB::Cursor |