… | |
… | |
6 | |
6 | |
7 | #include "EXTERN.h" |
7 | #include "EXTERN.h" |
8 | #include "perl.h" |
8 | #include "perl.h" |
9 | #include "XSUB.h" |
9 | #include "XSUB.h" |
10 | |
10 | |
|
|
11 | #include "schmorp.h" |
|
|
12 | |
11 | // perl stupidly defines these as macros, breaking |
13 | // perl stupidly defines these as argument-less macros, breaking |
12 | // lots and lots of code. |
14 | // lots and lots of code. |
13 | #undef open |
15 | #undef open |
14 | #undef close |
16 | #undef close |
15 | #undef abort |
17 | #undef abort |
16 | #undef malloc |
18 | #undef malloc |
… | |
… | |
56 | #endif |
58 | #endif |
57 | |
59 | |
58 | typedef char *bdb_filename; |
60 | typedef char *bdb_filename; |
59 | |
61 | |
60 | static SV *prepare_cb; |
62 | static SV *prepare_cb; |
|
|
63 | |
|
|
64 | static HV |
|
|
65 | *bdb_stash, |
|
|
66 | *bdb_env_stash, |
|
|
67 | *bdb_txn_stash, |
|
|
68 | *bdb_cursor_stash, |
|
|
69 | *bdb_db_stash, |
|
|
70 | *bdb_sequence_stash; |
61 | |
71 | |
62 | #if DB_VERSION_MINOR >= 6 |
72 | #if DB_VERSION_MINOR >= 6 |
63 | # define c_close close |
73 | # define c_close close |
64 | # define c_count count |
74 | # define c_count count |
65 | # define c_del del |
75 | # define c_del del |
… | |
… | |
149 | |
159 | |
150 | enum { |
160 | enum { |
151 | REQ_QUIT, |
161 | REQ_QUIT, |
152 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
162 | REQ_ENV_OPEN, REQ_ENV_CLOSE, REQ_ENV_TXN_CHECKPOINT, REQ_ENV_LOCK_DETECT, |
153 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
163 | REQ_ENV_MEMP_SYNC, REQ_ENV_MEMP_TRICKLE, REQ_ENV_DBREMOVE, REQ_ENV_DBRENAME, |
|
|
164 | REQ_ENV_LOG_ARCHIVE, |
154 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_UPGRADE, |
165 | REQ_DB_OPEN, REQ_DB_CLOSE, REQ_DB_COMPACT, REQ_DB_SYNC, REQ_DB_VERIFY, REQ_DB_UPGRADE, |
155 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
166 | REQ_DB_PUT, REQ_DB_EXISTS, REQ_DB_GET, REQ_DB_PGET, REQ_DB_DEL, REQ_DB_KEY_RANGE, |
156 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
167 | REQ_TXN_COMMIT, REQ_TXN_ABORT, REQ_TXN_FINISH, |
157 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
168 | REQ_C_CLOSE, REQ_C_COUNT, REQ_C_PUT, REQ_C_GET, REQ_C_PGET, REQ_C_DEL, |
158 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
169 | REQ_SEQ_OPEN, REQ_SEQ_CLOSE, REQ_SEQ_GET, REQ_SEQ_REMOVE, |
159 | }; |
170 | }; |
… | |
… | |
244 | } |
255 | } |
245 | |
256 | |
246 | static volatile unsigned int nreqs, nready, npending; |
257 | static volatile unsigned int nreqs, nready, npending; |
247 | static volatile unsigned int max_idle = 4; |
258 | static volatile unsigned int max_idle = 4; |
248 | static volatile unsigned int max_outstanding = 0xffffffff; |
259 | static volatile unsigned int max_outstanding = 0xffffffff; |
249 | static int respipe_osf [2], respipe [2] = { -1, -1 }; |
260 | static s_epipe respipe; |
250 | |
261 | |
251 | static mutex_t reslock = X_MUTEX_INIT; |
262 | static mutex_t reslock = X_MUTEX_INIT; |
252 | static mutex_t reqlock = X_MUTEX_INIT; |
263 | static mutex_t reqlock = X_MUTEX_INIT; |
253 | static cond_t reqwait = X_COND_INIT; |
264 | static cond_t reqwait = X_COND_INIT; |
254 | |
265 | |
… | |
… | |
377 | |
388 | |
378 | av_push (av, newSVnv (req->key_range.less)); |
389 | av_push (av, newSVnv (req->key_range.less)); |
379 | av_push (av, newSVnv (req->key_range.equal)); |
390 | av_push (av, newSVnv (req->key_range.equal)); |
380 | av_push (av, newSVnv (req->key_range.greater)); |
391 | av_push (av, newSVnv (req->key_range.greater)); |
381 | |
392 | |
|
|
393 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
394 | |
382 | SvREADONLY_off (req->sv1); |
395 | SvREADONLY_off (req->sv1); |
383 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
396 | sv_setsv_mg (req->sv1, newRV_noinc ((SV *)av)); |
|
|
397 | SvREFCNT_dec (av); |
384 | SvREFCNT_dec (req->sv1); |
398 | SvREFCNT_dec (req->sv1); |
385 | } |
399 | } |
386 | break; |
400 | break; |
387 | |
401 | |
388 | #if DB_VERSION_MINOR >= 3 |
402 | #if DB_VERSION_MINOR >= 3 |
… | |
… | |
395 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
409 | sv_setnv_mg (req->sv1, (NV)req->seq_t); |
396 | |
410 | |
397 | SvREFCNT_dec (req->sv1); |
411 | SvREFCNT_dec (req->sv1); |
398 | break; |
412 | break; |
399 | #endif |
413 | #endif |
|
|
414 | |
|
|
415 | case REQ_ENV_LOG_ARCHIVE: |
|
|
416 | { |
|
|
417 | AV *av = newAV (); |
|
|
418 | char **listp = (char **)req->buf1; |
|
|
419 | |
|
|
420 | if (listp) |
|
|
421 | while (*listp) |
|
|
422 | av_push (av, newSVpv (*listp, 0)), ++listp; |
|
|
423 | |
|
|
424 | av = (AV *)newRV_noinc ((SV *)av); |
|
|
425 | |
|
|
426 | SvREADONLY_off (req->sv1); |
|
|
427 | sv_setsv_mg (req->sv1, (SV *)av); |
|
|
428 | SvREFCNT_dec (av); |
|
|
429 | SvREFCNT_dec (req->sv1); |
|
|
430 | } |
|
|
431 | break; |
400 | } |
432 | } |
401 | |
433 | |
402 | errno = req->result; |
434 | errno = req->result; |
403 | |
435 | |
404 | if (req->callback) |
436 | if (req->callback) |
… | |
… | |
434 | free (req->buf3); |
466 | free (req->buf3); |
435 | |
467 | |
436 | Safefree (req); |
468 | Safefree (req); |
437 | } |
469 | } |
438 | |
470 | |
439 | #ifdef USE_SOCKETS_AS_HANDLES |
|
|
440 | # define TO_SOCKET(x) (win32_get_osfhandle (x)) |
|
|
441 | #else |
|
|
442 | # define TO_SOCKET(x) (x) |
|
|
443 | #endif |
|
|
444 | |
|
|
445 | static void |
471 | static void |
446 | create_respipe (void) |
472 | create_respipe (void) |
447 | { |
473 | { |
448 | #ifdef _WIN32 |
|
|
449 | int arg; /* argg */ |
|
|
450 | #endif |
|
|
451 | int old_readfd = respipe [0]; |
|
|
452 | |
|
|
453 | if (respipe [1] >= 0) |
|
|
454 | respipe_close (TO_SOCKET (respipe [1])); |
|
|
455 | |
|
|
456 | #ifdef _WIN32 |
|
|
457 | if (PerlSock_socketpair (AF_UNIX, SOCK_STREAM, 0, respipe)) |
|
|
458 | #else |
|
|
459 | if (pipe (respipe)) |
474 | if (s_epipe_renew (&respipe)) |
460 | #endif |
475 | croak ("BDB: unable to create event pipe"); |
461 | croak ("unable to initialize result pipe"); |
|
|
462 | |
|
|
463 | if (old_readfd >= 0) |
|
|
464 | { |
|
|
465 | if (dup2 (TO_SOCKET (respipe [0]), TO_SOCKET (old_readfd)) < 0) |
|
|
466 | croak ("unable to initialize result pipe(2)"); |
|
|
467 | |
|
|
468 | respipe_close (respipe [0]); |
|
|
469 | respipe [0] = old_readfd; |
|
|
470 | } |
|
|
471 | |
|
|
472 | #ifdef _WIN32 |
|
|
473 | arg = 1; |
|
|
474 | if (ioctlsocket (TO_SOCKET (respipe [0]), FIONBIO, &arg) |
|
|
475 | || ioctlsocket (TO_SOCKET (respipe [1]), FIONBIO, &arg)) |
|
|
476 | #else |
|
|
477 | if (fcntl (respipe [0], F_SETFL, O_NONBLOCK) |
|
|
478 | || fcntl (respipe [1], F_SETFL, O_NONBLOCK)) |
|
|
479 | #endif |
|
|
480 | croak ("unable to initialize result pipe(3)"); |
|
|
481 | |
|
|
482 | respipe_osf [0] = TO_SOCKET (respipe [0]); |
|
|
483 | respipe_osf [1] = TO_SOCKET (respipe [1]); |
|
|
484 | } |
476 | } |
485 | |
477 | |
486 | static void bdb_request (bdb_req req); |
478 | static void bdb_request (bdb_req req); |
487 | X_THREAD_PROC (bdb_proc); |
479 | X_THREAD_PROC (bdb_proc); |
488 | |
480 | |
… | |
… | |
624 | end_thread (); |
616 | end_thread (); |
625 | } |
617 | } |
626 | |
618 | |
627 | static void poll_wait (void) |
619 | static void poll_wait (void) |
628 | { |
620 | { |
629 | fd_set rfd; |
|
|
630 | |
|
|
631 | while (nreqs) |
621 | while (nreqs) |
632 | { |
622 | { |
633 | int size; |
623 | int size; |
634 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
624 | if (WORDACCESS_UNSAFE) X_LOCK (reslock); |
635 | size = res_queue.size; |
625 | size = res_queue.size; |
… | |
… | |
638 | if (size) |
628 | if (size) |
639 | return; |
629 | return; |
640 | |
630 | |
641 | maybe_start_thread (); |
631 | maybe_start_thread (); |
642 | |
632 | |
643 | FD_ZERO (&rfd); |
633 | s_epipe_wait (&respipe); |
644 | FD_SET (respipe [0], &rfd); |
|
|
645 | |
|
|
646 | PerlSock_select (respipe [0] + 1, &rfd, 0, 0, 0); |
|
|
647 | } |
634 | } |
648 | } |
635 | } |
649 | |
636 | |
650 | static int poll_cb (void) |
637 | static int poll_cb (void) |
651 | { |
638 | { |
… | |
… | |
671 | if (req) |
658 | if (req) |
672 | { |
659 | { |
673 | --npending; |
660 | --npending; |
674 | |
661 | |
675 | if (!res_queue.size) |
662 | if (!res_queue.size) |
676 | { |
|
|
677 | /* read any signals sent by the worker threads */ |
663 | /* read any signals sent by the worker threads */ |
678 | char buf [4]; |
664 | s_epipe_drain (&respipe); |
679 | while (respipe_read (respipe [0], buf, 4) == 4) |
|
|
680 | ; |
|
|
681 | } |
|
|
682 | } |
665 | } |
683 | |
666 | |
684 | X_UNLOCK (reslock); |
667 | X_UNLOCK (reslock); |
685 | |
668 | |
686 | if (!req) |
669 | if (!req) |
… | |
… | |
774 | break; |
757 | break; |
775 | #endif |
758 | #endif |
776 | |
759 | |
777 | case REQ_DB_SYNC: |
760 | case REQ_DB_SYNC: |
778 | req->result = req->db->sync (req->db, req->uint1); |
761 | req->result = req->db->sync (req->db, req->uint1); |
|
|
762 | break; |
|
|
763 | |
|
|
764 | case REQ_DB_VERIFY: |
|
|
765 | req->result = req->db->verify (req->db, req->buf1, req->buf2, 0, req->uint1); |
779 | break; |
766 | break; |
780 | |
767 | |
781 | case REQ_DB_UPGRADE: |
768 | case REQ_DB_UPGRADE: |
782 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
769 | req->result = req->db->upgrade (req->db, req->buf1, req->uint1); |
783 | break; |
770 | break; |
… | |
… | |
870 | case REQ_SEQ_REMOVE: |
857 | case REQ_SEQ_REMOVE: |
871 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
858 | req->result = req->seq->remove (req->seq, req->txn, req->uint1); |
872 | break; |
859 | break; |
873 | #endif |
860 | #endif |
874 | |
861 | |
|
|
862 | case REQ_ENV_LOG_ARCHIVE: |
|
|
863 | { |
|
|
864 | char **listp = 0; /* DB_ARCH_REMOVE does not touch listp, contrary to docs */ |
|
|
865 | req->result = req->env->log_archive (req->env, &listp, req->uint1); |
|
|
866 | req->buf1 = (char *)listp; |
|
|
867 | } |
|
|
868 | break; |
|
|
869 | |
875 | default: |
870 | default: |
876 | req->result = ENOSYS; |
871 | req->result = ENOSYS; |
877 | break; |
872 | break; |
878 | } |
873 | } |
879 | |
874 | |
… | |
… | |
890 | /* try to distribute timeouts somewhat evenly */ |
885 | /* try to distribute timeouts somewhat evenly */ |
891 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
886 | ts.tv_nsec = ((unsigned long)self & 1023UL) * (1000000000UL / 1024UL); |
892 | |
887 | |
893 | for (;;) |
888 | for (;;) |
894 | { |
889 | { |
895 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
890 | ts.tv_sec = time (0) + IDLE_TIMEOUT; |
896 | |
891 | |
897 | X_LOCK (reqlock); |
892 | X_LOCK (reqlock); |
898 | |
893 | |
899 | for (;;) |
894 | for (;;) |
900 | { |
895 | { |
… | |
… | |
945 | X_LOCK (reslock); |
940 | X_LOCK (reslock); |
946 | |
941 | |
947 | ++npending; |
942 | ++npending; |
948 | |
943 | |
949 | if (!reqq_push (&res_queue, req)) |
944 | if (!reqq_push (&res_queue, req)) |
950 | /* write a dummy byte to the pipe so fh becomes ready */ |
945 | s_epipe_signal (&respipe); |
951 | respipe_write (respipe_osf [1], (const void *)&respipe_osf, 1); |
|
|
952 | |
946 | |
953 | self->req = 0; |
947 | self->req = 0; |
954 | worker_clear (self); |
948 | worker_clear (self); |
955 | |
949 | |
956 | X_UNLOCK (reslock); |
950 | X_UNLOCK (reslock); |
… | |
… | |
1032 | (void)0; |
1026 | (void)0; |
1033 | |
1027 | |
1034 | #define REQ_SEND \ |
1028 | #define REQ_SEND \ |
1035 | req_send (req) |
1029 | req_send (req) |
1036 | |
1030 | |
1037 | #define SvPTR(var, arg, type, class, nullok) \ |
1031 | #define SvPTR(var, arg, type, stash, class, nullok) \ |
1038 | if (!SvOK (arg)) \ |
1032 | if (!SvOK (arg)) \ |
1039 | { \ |
1033 | { \ |
1040 | if (nullok != 1) \ |
1034 | if (nullok != 1) \ |
1041 | croak (# var " must be a " # class " object, not undef"); \ |
1035 | croak (# var " must be a " # class " object, not undef"); \ |
1042 | \ |
1036 | \ |
1043 | (var) = 0; \ |
1037 | (var) = 0; \ |
1044 | } \ |
1038 | } \ |
1045 | else if (sv_derived_from ((arg), # class)) \ |
1039 | else if (SvSTASH (SvRV (arg)) == stash || sv_derived_from ((arg), # class)) \ |
1046 | { \ |
1040 | { \ |
1047 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1041 | IV tmp = SvIV ((SV*) SvRV (arg)); \ |
1048 | (var) = INT2PTR (type, tmp); \ |
1042 | (var) = INT2PTR (type, tmp); \ |
1049 | if (!var && nullok != 2) \ |
1043 | if (!var && nullok != 2) \ |
1050 | croak (# var " is not a valid " # class " object anymore"); \ |
1044 | croak (# var " is not a valid " # class " object anymore"); \ |
… | |
… | |
1053 | croak (# var " is not of type " # class); |
1047 | croak (# var " is not of type " # class); |
1054 | |
1048 | |
1055 | #define ARG_MUTABLE(name) \ |
1049 | #define ARG_MUTABLE(name) \ |
1056 | if (SvREADONLY (name)) \ |
1050 | if (SvREADONLY (name)) \ |
1057 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
1051 | croak ("argument " #name " is read-only/constant, but the request requires it to be mutable"); |
|
|
1052 | |
|
|
1053 | static SV * |
|
|
1054 | newSVptr (void *ptr, HV *stash) |
|
|
1055 | { |
|
|
1056 | SV *rv = NEWSV (0, 0); |
|
|
1057 | sv_upgrade (rv, SVt_PVMG); |
|
|
1058 | sv_setiv (rv, PTR2IV (ptr)); |
|
|
1059 | |
|
|
1060 | return sv_bless (newRV_noinc (rv), stash); |
|
|
1061 | } |
1058 | |
1062 | |
1059 | static void |
1063 | static void |
1060 | ptr_nuke (SV *sv) |
1064 | ptr_nuke (SV *sv) |
1061 | { |
1065 | { |
1062 | assert (SvROK (sv)); |
1066 | assert (SvROK (sv)); |
… | |
… | |
1133 | } |
1137 | } |
1134 | |
1138 | |
1135 | return 0; |
1139 | return 0; |
1136 | } |
1140 | } |
1137 | |
1141 | |
|
|
1142 | /*****************************************************************************/ |
|
|
1143 | |
|
|
1144 | #if 0 |
|
|
1145 | static int |
|
|
1146 | bt_pfxc_compare (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1147 | { |
|
|
1148 | ssize_t size1 = dbt1->size; |
|
|
1149 | ssize_t size2 = dbt2->size; |
|
|
1150 | int res = memcmp ((void *)dbt1->data, (void *)dbt2->data, |
|
|
1151 | size1 <= size2 ? size1 : size2); |
|
|
1152 | |
|
|
1153 | if (res) |
|
|
1154 | return res; |
|
|
1155 | else if (size1 - size2) |
|
|
1156 | return size1 - size2; |
|
|
1157 | else |
|
|
1158 | return 0; |
|
|
1159 | } |
|
|
1160 | |
|
|
1161 | static size_t |
|
|
1162 | bt_pfxc_prefix_x (DB *db, const DBT *dbt1, const DBT *dbt2) |
|
|
1163 | { |
|
|
1164 | ssize_t size1 = dbt1->size; |
|
|
1165 | ssize_t size2 = dbt2->size; |
|
|
1166 | u_int8_t *p1 = (u_int8_t *)dbt1->data; |
|
|
1167 | u_int8_t *p2 = (u_int8_t *)dbt2->data; |
|
|
1168 | u_int8_t *pe = p1 + (size1 <= size2 ? size1 : size2); |
|
|
1169 | |
|
|
1170 | while (p1 < pe) |
|
|
1171 | if (*p1++ != *p2++) |
|
|
1172 | return p1 - (u_int8_t *)dbt1->data - 1; |
|
|
1173 | |
|
|
1174 | if (size1 < size2) return size1 + 1; |
|
|
1175 | if (size1 > size2) return size2 + 1; |
|
|
1176 | |
|
|
1177 | return size1; |
|
|
1178 | } |
|
|
1179 | #endif |
|
|
1180 | |
|
|
1181 | /*****************************************************************************/ |
|
|
1182 | |
1138 | /* stupid windows defines CALLBACK as well */ |
1183 | /* stupid windows defines CALLBACK as well */ |
1139 | #undef CALLBACK |
1184 | #undef CALLBACK |
1140 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1185 | #define CALLBACK SV *cb = pop_callback (&items, ST (items - 1)); |
1141 | |
1186 | |
1142 | MODULE = BDB PACKAGE = BDB |
1187 | MODULE = BDB PACKAGE = BDB |
1143 | |
1188 | |
1144 | PROTOTYPES: ENABLE |
1189 | PROTOTYPES: ENABLE |
1145 | |
1190 | |
1146 | BOOT: |
1191 | BOOT: |
1147 | { |
1192 | { |
1148 | HV *stash = gv_stashpv ("BDB", 1); |
|
|
1149 | |
|
|
1150 | static const struct { |
1193 | static const struct { |
1151 | const char *name; |
1194 | const char *name; |
1152 | IV iv; |
1195 | IV iv; |
1153 | } *civ, const_iv[] = { |
1196 | } *civ, const_iv[] = { |
1154 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
1197 | #define const_iv(name) { # name, (IV)DB_ ## name }, |
… | |
… | |
1278 | const_iv (REP_UNAVAIL) |
1321 | const_iv (REP_UNAVAIL) |
1279 | const_iv (RUNRECOVERY) |
1322 | const_iv (RUNRECOVERY) |
1280 | const_iv (SECONDARY_BAD) |
1323 | const_iv (SECONDARY_BAD) |
1281 | const_iv (VERIFY_BAD) |
1324 | const_iv (VERIFY_BAD) |
1282 | |
1325 | |
|
|
1326 | const_iv (SALVAGE) |
|
|
1327 | const_iv (AGGRESSIVE) |
|
|
1328 | const_iv (PRINTABLE) |
|
|
1329 | const_iv (NOORDERCHK) |
|
|
1330 | const_iv (ORDERCHKONLY) |
|
|
1331 | |
|
|
1332 | const_iv (ARCH_ABS) |
|
|
1333 | const_iv (ARCH_DATA) |
|
|
1334 | const_iv (ARCH_LOG) |
|
|
1335 | const_iv (ARCH_REMOVE) |
|
|
1336 | |
1283 | const_iv (VERB_DEADLOCK) |
1337 | const_iv (VERB_DEADLOCK) |
1284 | const_iv (VERB_RECOVERY) |
1338 | const_iv (VERB_RECOVERY) |
1285 | const_iv (VERB_REPLICATION) |
1339 | const_iv (VERB_REPLICATION) |
1286 | const_iv (VERB_WAITSFOR) |
1340 | const_iv (VERB_WAITSFOR) |
1287 | |
1341 | |
… | |
… | |
1320 | const_iv (PRIORITY_VERY_LOW) |
1374 | const_iv (PRIORITY_VERY_LOW) |
1321 | const_iv (PRIORITY_LOW) |
1375 | const_iv (PRIORITY_LOW) |
1322 | const_iv (PRIORITY_DEFAULT) |
1376 | const_iv (PRIORITY_DEFAULT) |
1323 | const_iv (PRIORITY_HIGH) |
1377 | const_iv (PRIORITY_HIGH) |
1324 | const_iv (PRIORITY_VERY_HIGH) |
1378 | const_iv (PRIORITY_VERY_HIGH) |
|
|
1379 | const_iv (IGNORE_LEASE) |
1325 | #endif |
1380 | #endif |
1326 | #if DB_VERSION_MINOR >= 7 |
1381 | #if DB_VERSION_MINOR >= 7 |
1327 | const_iv (IGNORE_LEASE) |
|
|
1328 | //const_iv (MULTIPLE_KEY) |
1382 | //const_iv (MULTIPLE_KEY) |
1329 | const_iv (LOG_DIRECT) |
1383 | const_iv (LOG_DIRECT) |
1330 | const_iv (LOG_DSYNC) |
1384 | const_iv (LOG_DSYNC) |
1331 | const_iv (LOG_AUTO_REMOVE) |
1385 | const_iv (LOG_AUTO_REMOVE) |
1332 | const_iv (LOG_IN_MEMORY) |
1386 | const_iv (LOG_IN_MEMORY) |
… | |
… | |
1339 | const_iv (LOG_INMEMORY) |
1393 | const_iv (LOG_INMEMORY) |
1340 | # endif |
1394 | # endif |
1341 | #endif |
1395 | #endif |
1342 | }; |
1396 | }; |
1343 | |
1397 | |
|
|
1398 | bdb_stash = gv_stashpv ("BDB" , 1); |
|
|
1399 | bdb_env_stash = gv_stashpv ("BDB::Env" , 1); |
|
|
1400 | bdb_txn_stash = gv_stashpv ("BDB::Txn" , 1); |
|
|
1401 | bdb_cursor_stash = gv_stashpv ("BDB::Cursor" , 1); |
|
|
1402 | bdb_db_stash = gv_stashpv ("BDB::Db" , 1); |
|
|
1403 | bdb_sequence_stash = gv_stashpv ("BDB::Sequence", 1); |
|
|
1404 | |
1344 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1405 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) |
1345 | newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); |
1406 | newCONSTSUB (bdb_stash, (char *)civ->name, newSViv (civ->iv)); |
1346 | |
1407 | |
1347 | prepare_cb = &PL_sv_undef; |
1408 | prepare_cb = &PL_sv_undef; |
1348 | |
1409 | |
1349 | { |
1410 | { |
1350 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1411 | /* we currently only allow version, minor-version and patchlevel to go up to 255 */ |
1351 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1412 | char vstring[3] = { DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH }; |
1352 | |
1413 | |
1353 | newCONSTSUB (stash, "VERSION_v", newSVpvn (vstring, 3)); |
1414 | newCONSTSUB (bdb_stash, "VERSION_v", newSVpvn (vstring, 3)); |
1354 | } |
1415 | } |
1355 | |
1416 | |
1356 | newCONSTSUB (stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1417 | newCONSTSUB (bdb_stash, "VERSION_STRING", newSVpv (DB_VERSION_STRING, 0)); |
1357 | |
1418 | |
1358 | create_respipe (); |
1419 | create_respipe (); |
1359 | |
1420 | |
1360 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1421 | X_THREAD_ATFORK (atfork_prepare, atfork_parent, atfork_child); |
1361 | patch_errno (); |
1422 | patch_errno (); |
… | |
… | |
1439 | |
1500 | |
1440 | int |
1501 | int |
1441 | poll_fileno () |
1502 | poll_fileno () |
1442 | PROTOTYPE: |
1503 | PROTOTYPE: |
1443 | CODE: |
1504 | CODE: |
1444 | RETVAL = respipe [0]; |
1505 | RETVAL = s_epipe_fd (&respipe); |
1445 | OUTPUT: |
1506 | OUTPUT: |
1446 | RETVAL |
1507 | RETVAL |
1447 | |
1508 | |
1448 | int |
1509 | int |
1449 | poll_cb (...) |
1510 | poll_cb (...) |
… | |
… | |
1633 | dREQ (REQ_ENV_DBRENAME, 2); |
1694 | dREQ (REQ_ENV_DBRENAME, 2); |
1634 | req->env = env; |
1695 | req->env = env; |
1635 | req->buf1 = strdup_ornull (file); |
1696 | req->buf1 = strdup_ornull (file); |
1636 | req->buf2 = strdup_ornull (database); |
1697 | req->buf2 = strdup_ornull (database); |
1637 | req->buf3 = strdup_ornull (newname); |
1698 | req->buf3 = strdup_ornull (newname); |
|
|
1699 | req->uint1 = flags; |
|
|
1700 | REQ_SEND; |
|
|
1701 | } |
|
|
1702 | |
|
|
1703 | void |
|
|
1704 | db_env_log_archive (DB_ENV *env, SV_mutable *listp, U32 flags = 0, SV *callback = 0) |
|
|
1705 | PREINIT: |
|
|
1706 | CALLBACK |
|
|
1707 | CODE: |
|
|
1708 | { |
|
|
1709 | dREQ (REQ_ENV_LOG_ARCHIVE, 1); |
|
|
1710 | req->sv1 = SvREFCNT_inc (listp); |
|
|
1711 | req->env = env; |
1638 | req->uint1 = flags; |
1712 | req->uint1 = flags; |
1639 | REQ_SEND; |
1713 | REQ_SEND; |
1640 | } |
1714 | } |
1641 | |
1715 | |
1642 | DB * |
1716 | DB * |
… | |
… | |
1714 | req->uint1 = flags; |
1788 | req->uint1 = flags; |
1715 | REQ_SEND; |
1789 | REQ_SEND; |
1716 | } |
1790 | } |
1717 | |
1791 | |
1718 | void |
1792 | void |
|
|
1793 | db_verify (DB *db, bdb_filename file, bdb_filename database = 0, SV *dummy = 0, U32 flags = 0, SV *callback = 0) |
|
|
1794 | PREINIT: |
|
|
1795 | CALLBACK |
|
|
1796 | CODE: |
|
|
1797 | { |
|
|
1798 | dREQ (REQ_DB_VERIFY, 1); |
|
|
1799 | ptr_nuke (ST (0)); /* verify destroys the database handle, hopefully it is freed as well */ |
|
|
1800 | req->db = db; |
|
|
1801 | req->buf1 = strdup (file); |
|
|
1802 | req->buf2 = strdup_ornull (database); |
|
|
1803 | req->uint1 = flags; |
|
|
1804 | REQ_SEND; |
|
|
1805 | } |
|
|
1806 | |
|
|
1807 | void |
1719 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1808 | db_upgrade (DB *db, bdb_filename file, U32 flags = 0, SV *callback = 0) |
1720 | PREINIT: |
1809 | PREINIT: |
1721 | CALLBACK |
1810 | CALLBACK |
1722 | CODE: |
1811 | CODE: |
1723 | { |
1812 | { |
1724 | dREQ (REQ_DB_SYNC, 1); |
1813 | dREQ (REQ_DB_UPGRADE, 1); |
1725 | req->db = db; |
1814 | req->db = db; |
1726 | req->buf1 = strdup (file); |
1815 | req->buf1 = strdup (file); |
1727 | req->uint1 = flags; |
1816 | req->uint1 = flags; |
1728 | REQ_SEND; |
1817 | REQ_SEND; |
1729 | } |
1818 | } |