2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid[] = "@(#)bt_recno.c 10.15 (Sleepycat) 9/3/97";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
28 static int __ram_add __P((DB *, db_recno_t *, DBT *, int, int));
29 static int __ram_c_close __P((DBC *));
30 static int __ram_c_del __P((DBC *, int));
31 static int __ram_c_get __P((DBC *, DBT *, DBT *, int));
32 static int __ram_c_put __P((DBC *, DBT *, DBT *, int));
33 static int __ram_fmap __P((DB *, db_recno_t));
34 static int __ram_get __P((DB *, DB_TXN *, DBT *, DBT *, int));
35 static int __ram_put __P((DB *, DB_TXN *, DBT *, DBT *, int));
36 static int __ram_source __P((DB *, RECNO *, const char *));
37 static int __ram_sync __P((DB *, int));
38 static int __ram_update __P((DB *, db_recno_t, int));
39 static int __ram_vmap __P((DB *, db_recno_t));
40 static int __ram_writeback __P((DB *));
43 * If we're renumbering records, then we have to detect in the cursor that a
44 * record was deleted, and adjust the cursor as necessary. If not renumbering
45 * records, then we can detect this by looking at the actual record, so we
46 * ignore the cursor delete flag.
48 #define CD_SET(dbp, cp) { \
49 if (F_ISSET(dbp, DB_RE_RENUMBER)) \
50 F_SET(cp, CR_DELETED); \
52 #define CD_CLR(dbp, cp) { \
53 if (F_ISSET(dbp, DB_RE_RENUMBER)) \
54 F_CLR(cp, CR_DELETED); \
56 #define CD_ISSET(dbp, cp) \
57 (F_ISSET(dbp, DB_RE_RENUMBER) && F_ISSET(cp, CR_DELETED))
61 * Recno open function.
63 * PUBLIC: int __ram_open __P((DB *, DBTYPE, DB_INFO *));
66 __ram_open(dbp, type, dbinfo)
77 /* Allocate and initialize the private RECNO structure. */
78 if ((rp = (RECNO *)calloc(1, sizeof(*rp))) == NULL)
83 * If the user specified a source tree, open it and map it in.
86 * We don't complain if the user specified transactions or
87 * threads. It's possible to make it work, but you'd better
88 * know what you're doing!
90 if (dbinfo->re_source == NULL) {
95 __ram_source(dbp, rp, dbinfo->re_source)) != 0)
99 /* Copy delimiter, length and padding values. */
101 F_ISSET(dbp, DB_RE_DELIMITER) ? dbinfo->re_delim : '\n';
102 rp->re_pad = F_ISSET(dbp, DB_RE_PAD) ? dbinfo->re_pad : ' ';
104 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
105 if ((rp->re_len = dbinfo->re_len) == 0) {
107 "record length must be greater than 0");
117 F_SET(rp, RECNO_EOF);
120 /* Open the underlying btree. */
121 if ((ret = __bam_open(dbp, DB_RECNO, dbinfo)) != 0)
124 /* Set the routines necessary to make it look like a recno tree. */
125 dbp->cursor = __ram_cursor;
126 dbp->del = __ram_delete;
127 dbp->get = __ram_get;
128 dbp->put = __ram_put;
129 dbp->sync = __ram_sync;
131 /* Link in the private recno structure. */
132 ((BTREE *)dbp->internal)->bt_recno = rp;
134 /* If we're snapshotting an underlying source file, do it now. */
135 if (dbinfo != NULL && F_ISSET(dbinfo, DB_SNAPSHOT))
136 if ((ret = __ram_snapshot(dbp)) != 0 && ret != DB_NOTFOUND)
141 err: /* If we mmap'd a source file, discard it. */
142 if (rp->re_smap != NULL)
143 (void)__db_munmap(rp->re_smap, rp->re_msize);
145 /* If we opened a source file, discard it. */
147 (void)__db_close(rp->re_fd);
148 if (rp->re_source != NULL)
149 FREES(rp->re_source);
151 /* If we allocated room for key/data return, discard it. */
153 if (t->bt_rkey.data != NULL)
154 free(t->bt_rkey.data);
156 FREE(rp, sizeof(*rp));
163 * Recno db->cursor function.
165 * PUBLIC: int __ram_cursor __P((DB *, DB_TXN *, DBC **));
168 __ram_cursor(dbp, txn, dbcp)
176 DEBUG_LWRITE(dbp, txn, "ram_cursor", NULL, NULL, 0);
178 if ((dbc = (DBC *)calloc(1, sizeof(DBC))) == NULL)
180 if ((cp = (RCURSOR *)calloc(1, sizeof(RCURSOR))) == NULL) {
186 cp->recno = RECNO_OOB;
191 dbc->c_close = __ram_c_close;
192 dbc->c_del = __ram_c_del;
193 dbc->c_get = __ram_c_get;
194 dbc->c_put = __ram_c_put;
196 /* All cursor structures hang off the main DB structure. */
198 TAILQ_INSERT_HEAD(&dbp->curs_queue, dbc, links);
199 DB_THREAD_UNLOCK(dbp);
207 * Recno db->get function.
210 __ram_get(argdbp, txn, key, data, flags)
221 int exact, ret, stack;
225 DEBUG_LWRITE(argdbp, txn, "ram_get", key, NULL, flags);
227 /* Check for invalid flags. */
228 if ((ret = __db_getchk(argdbp, key, data, flags)) != 0)
231 GETHANDLE(argdbp, txn, &dbp, ret);
234 /* Check the user's record number and fill in as necessary. */
235 if ((ret = __ram_getno(dbp, key, &recno, 0)) != 0)
238 /* Search the tree for the record. */
239 if ((ret = __bam_rsearch(dbp, &recno, S_FIND, 1, &exact)) != 0)
242 return (DB_NOTFOUND);
246 indx = t->bt_csp->indx;
248 /* If the record has already been deleted, we couldn't have found it. */
249 if (B_DISSET(GET_BKEYDATA(h, indx)->type)) {
254 /* Return the data item. */
256 h, indx, data, &t->bt_rdata.data, &t->bt_rdata.ulen);
259 done: /* Discard the stack. */
269 * Recno db->put function.
272 __ram_put(argdbp, txn, key, data, flags)
283 DEBUG_LWRITE(argdbp, txn, "ram_put", key, data, flags);
285 /* Check for invalid flags. */
286 if ((ret = __db_putchk(argdbp,
287 key, data, flags, F_ISSET(argdbp, DB_AM_RDONLY), 0)) != 0)
290 GETHANDLE(argdbp, txn, &dbp, ret);
293 * If we're appending to the tree, make sure we've read in all of
294 * the backing source file. Otherwise, check the user's record
295 * number and fill in as necessary.
297 ret = LF_ISSET(DB_APPEND) ?
298 __ram_snapshot(dbp) : __ram_getno(dbp, key, &recno, 1);
300 /* Add the record. */
302 ret = __ram_add(dbp, &recno, data, flags, 0);
304 /* If we're appending to the tree, we have to return the record. */
305 if (ret == 0 && LF_ISSET(DB_APPEND)) {
307 ret = __db_retcopy(key, &recno, sizeof(recno),
308 &t->bt_rkey.data, &t->bt_rkey.ulen, dbp->db_malloc);
317 * Recno db->sync function.
320 __ram_sync(argdbp, flags)
327 DEBUG_LWRITE(argdbp, NULL, "ram_sync", NULL, NULL, flags);
329 /* Sync the underlying btree. */
330 if ((ret = __bam_sync(argdbp, flags)) != 0)
333 /* Copy back the backing source file. */
334 GETHANDLE(argdbp, NULL, &dbp, ret);
335 ret = __ram_writeback(dbp);
343 * Recno db->close function.
345 * PUBLIC: int __ram_close __P((DB *));
353 DEBUG_LWRITE(argdbp, NULL, "ram_close", NULL, NULL, 0);
355 rp = ((BTREE *)argdbp->internal)->bt_recno;
357 /* Close any underlying mmap region. */
358 if (rp->re_smap != NULL)
359 (void)__db_munmap(rp->re_smap, rp->re_msize);
361 /* Close any backing source file descriptor. */
363 (void)__db_close(rp->re_fd);
365 /* Free any backing source file name. */
366 if (rp->re_source != NULL)
367 FREES(rp->re_source);
369 /* Free allocated memory. */
370 FREE(rp, sizeof(RECNO));
371 ((BTREE *)argdbp->internal)->bt_recno = NULL;
373 /* Close the underlying btree. */
374 return (__bam_close(argdbp));
379 * Recno cursor->close function.
387 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_close", NULL, NULL, 0);
391 /* Remove the cursor from the queue. */
393 TAILQ_REMOVE(&dbp->curs_queue, dbc, links);
394 DB_THREAD_UNLOCK(dbp);
396 /* Discard the structures. */
397 FREE(dbc->internal, sizeof(RCURSOR));
398 FREE(dbc, sizeof(DBC));
405 * Recno cursor->c_del function.
408 __ram_c_del(dbc, flags)
416 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_del", NULL, NULL, flags);
420 /* Check for invalid flags. */
421 if ((ret = __db_cdelchk(dbc->dbp, flags,
422 F_ISSET(dbc->dbp, DB_AM_RDONLY), cp->recno != RECNO_OOB)) != 0)
425 /* If already deleted, return failure. */
426 if (CD_ISSET(dbc->dbp, cp))
427 return (DB_KEYEMPTY);
429 /* Build a normal delete request. */
430 memset(&key, 0, sizeof(key));
431 key.data = &cp->recno;
432 key.size = sizeof(db_recno_t);
433 if ((ret = __ram_delete(dbc->dbp, dbc->txn, &key, 0)) == 0)
434 CD_SET(dbc->dbp, cp);
441 * Recno cursor->c_get function.
444 __ram_c_get(dbc, key, data, flags)
454 DEBUG_LREAD(dbc->dbp, dbc->txn, "ram_c_get",
455 flags == DB_SET || flags == DB_SET_RANGE ? key : NULL,
461 /* Check for invalid flags. */
462 if ((ret = __db_cgetchk(dbc->dbp,
463 key, data, flags, cp->recno != RECNO_OOB)) != 0)
466 GETHANDLE(dbc->dbp, dbc->txn, &dbp, ret);
469 /* Initialize the cursor for a new retrieval. */
472 retry: /* Update the record number. */
475 if (CD_ISSET(dbp, cp)) {
477 return (DB_KEYEMPTY);
481 if (CD_ISSET(dbp, cp))
483 if (cp->recno != RECNO_OOB) {
493 if (cp->recno != RECNO_OOB) {
495 return (DB_NOTFOUND);
502 if (((ret = __ram_snapshot(dbp)) != 0) && ret != DB_NOTFOUND)
504 if ((ret = __bam_nrecs(dbp, &cp->recno)) != 0)
507 return (DB_NOTFOUND);
511 if ((ret = __ram_getno(dbp, key, &cp->recno, 0)) != 0)
517 * Return the key if the user didn't give us one, and then pass it
520 if (flags != DB_SET && flags != DB_SET_RANGE &&
521 (ret = __db_retcopy(key, &cp->recno, sizeof(cp->recno),
522 &t->bt_rkey.data, &t->bt_rkey.ulen, dbp->db_malloc)) != 0)
526 * The cursor was reset, so the delete adjustment is no
532 * Retrieve the record.
534 * Skip any keys that don't really exist.
536 if ((ret = __ram_get(dbp, dbc->txn, key, data, 0)) != 0)
537 if (ret == DB_KEYEMPTY &&
538 (flags == DB_NEXT || flags == DB_PREV))
550 * Recno cursor->c_put function.
553 __ram_c_put(dbc, key, data, flags)
564 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_put", NULL, data, flags);
568 if ((ret = __db_cputchk(dbc->dbp, key, data, flags,
569 F_ISSET(dbc->dbp, DB_AM_RDONLY), cp->recno != RECNO_OOB)) != 0)
572 GETHANDLE(dbc->dbp, dbc->txn, &dbp, ret);
575 /* Initialize the cursor for a new retrieval. */
579 * To split, we need a valid key for the page. Since it's a cursor,
580 * we have to build one.
582 * The split code discards all short-term locks and stack pages.
585 split: arg = &cp->recno;
586 if ((ret = __bam_split(dbp, arg)) != 0)
590 if ((ret = __bam_rsearch(dbp, &cp->recno, S_INSERT, 1, &exact)) != 0)
596 if ((ret = __bam_iitem(dbp, &t->bt_csp->page,
597 &t->bt_csp->indx, key, data, flags, 0)) == DB_NEEDSPLIT) {
598 if ((ret = __bam_stkrel(dbp)) != 0)
602 if ((ret = __bam_stkrel(dbp)) != 0)
605 if (flags != DB_CURRENT) {
606 /* Adjust the counts. */
607 if ((ret = __bam_adjust(dbp, t, 1)) != 0)
612 /* Adjust the cursors. */
613 __ram_ca(dbp, cp->recno, CA_IAFTER);
615 /* Set this cursor to reference the new record. */
616 cp->recno = copy.recno + 1;
619 /* Adjust the cursors. */
620 __ram_ca(dbp, cp->recno, CA_IBEFORE);
622 /* Set this cursor to reference the new record. */
623 cp->recno = copy.recno;
630 * The cursor was reset, so the delete adjustment is no
646 * PUBLIC: void __ram_ca __P((DB *, db_recno_t, ca_recno_arg));
649 __ram_ca(dbp, recno, op)
658 * Adjust the cursors. See the comment in __bam_ca_delete().
661 for (dbc = TAILQ_FIRST(&dbp->curs_queue);
662 dbc != NULL; dbc = TAILQ_NEXT(dbc, links)) {
663 cp = (RCURSOR *)dbc->internal;
666 if (recno > cp->recno)
670 if (recno > cp->recno)
674 if (recno >= cp->recno)
679 DB_THREAD_UNLOCK(dbp);
685 * Display the current recno cursor list.
695 for (dbc = TAILQ_FIRST(&dbp->curs_queue);
696 dbc != NULL; dbc = TAILQ_NEXT(dbc, links)) {
697 cp = (RCURSOR *)dbc->internal;
699 "%#0x: recno: %lu\n", (u_int)cp, (u_long)cp->recno);
701 DB_THREAD_UNLOCK(dbp);
708 * Check the user's record number, and make sure we've seen it.
710 * PUBLIC: int __ram_getno __P((DB *, const DBT *, db_recno_t *, int));
713 __ram_getno(dbp, key, rep, can_create)
721 /* Check the user's record number. */
722 if ((recno = *(db_recno_t *)key->data) == 0) {
723 __db_err(dbp->dbenv, "illegal record number of 0");
730 * Btree can neither create records or read them in. Recno can
731 * do both, see if we can find the record.
733 return (dbp->type == DB_RECNO ?
734 __ram_update(dbp, recno, can_create) : 0);
739 * Read in any remaining records from the backing input file.
741 * PUBLIC: int __ram_snapshot __P((DB *));
747 return (__ram_update(dbp, DB_MAX_RECORDS, 0));
752 * Ensure the tree has records up to and including the specified one.
755 __ram_update(dbp, recno, can_create)
769 * If we can't create records and we've read the entire backing input
772 if (!can_create && F_ISSET(rp, RECNO_EOF))
776 * If we haven't seen this record yet, try to get it from the original
779 if ((ret = __bam_nrecs(dbp, &nrecs)) != 0)
781 if (!F_ISSET(rp, RECNO_EOF) && recno > nrecs) {
782 if ((ret = rp->re_irec(dbp, recno)) != 0)
784 if ((ret = __bam_nrecs(dbp, &nrecs)) != 0)
789 * If we can create records, create empty ones up to the requested
792 if (!can_create || recno <= nrecs + 1)
795 t->bt_rdata.dlen = 0;
796 t->bt_rdata.doff = 0;
797 t->bt_rdata.flags = 0;
798 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
799 if (t->bt_rdata.ulen < rp->re_len) {
800 t->bt_rdata.data = t->bt_rdata.data == NULL ?
801 (void *)malloc(rp->re_len) :
802 (void *)realloc(t->bt_rdata.data, rp->re_len);
803 if (t->bt_rdata.data == NULL) {
804 t->bt_rdata.ulen = 0;
807 t->bt_rdata.ulen = rp->re_len;
809 t->bt_rdata.size = rp->re_len;
810 memset(t->bt_rdata.data, rp->re_pad, rp->re_len);
812 t->bt_rdata.size = 0;
814 while (recno > ++nrecs)
815 if ((ret = __ram_add(dbp,
816 &nrecs, &t->bt_rdata, 0, BI_DELETED)) != 0)
823 * Load information about the backing file.
826 __ram_source(dbp, rp, fname)
834 if ((ret = __db_appname(dbp->dbenv,
835 DB_APP_DATA, NULL, fname, NULL, &rp->re_source)) != 0)
838 oflags = F_ISSET(dbp, DB_AM_RDONLY) ? DB_RDONLY : 0;
840 __db_fdopen(rp->re_source, oflags, oflags, 0, &rp->re_fd)) != 0) {
841 __db_err(dbp->dbenv, "%s: %s", rp->re_source, strerror(ret));
847 * We'd like to test to see if the file is too big to mmap. Since we
848 * don't know what size or type off_t's or size_t's are, or the largest
849 * unsigned integral type is, or what random insanity the local C
850 * compiler will perpetrate, doing the comparison in a portable way is
851 * flatly impossible. Hope that mmap fails if the file is too large.
854 __db_stat(dbp->dbenv, rp->re_source, rp->re_fd, &size, NULL)) != 0)
857 F_SET(rp, RECNO_EOF);
861 if ((ret = __db_mmap(rp->re_fd, (size_t)size, 1, 1, &rp->re_smap)) != 0)
863 rp->re_cmap = rp->re_smap;
864 rp->re_emap = (u_int8_t *)rp->re_smap + (rp->re_msize = size);
865 rp->re_irec = F_ISSET(dbp, DB_RE_FIXEDLEN) ? __ram_fmap : __ram_vmap;
868 err: FREES(rp->re_source)
874 * Rewrite the backing file.
885 u_int8_t delim, *pad;
887 rp = ((BTREE *)dbp->internal)->bt_recno;
889 /* If the file wasn't modified, we're done. */
890 if (!F_ISSET(rp, RECNO_MODIFIED))
893 /* If there's no backing source file, we're done. */
894 if (rp->re_source == NULL) {
895 F_CLR(rp, RECNO_MODIFIED);
900 * Read any remaining records into the tree.
903 * This is why we can't support transactions when applications specify
904 * backing (re_source) files. At this point we have to read in the
905 * rest of the records from the file so that we can write all of the
906 * records back out again, which could modify a page for which we'd
907 * have to log changes and which we don't have locked. This could be
908 * partially fixed by taking a snapshot of the entire file during the
909 * db_open(), or, since db_open() isn't transaction protected, as part
910 * of the first DB operation. But, if a checkpoint occurs then, the
911 * part of the log holding the copy of the file could be discarded, and
912 * that would make it impossible to recover in the face of disaster.
913 * This could all probably be fixed, but it would require transaction
914 * protecting the backing source file, i.e. mpool would have to know
915 * about it, and we don't want to go there.
917 if ((ret = __ram_snapshot(dbp)) != 0 && ret != DB_NOTFOUND)
922 * Close any underlying mmap region. This is required for Windows NT
923 * (4.0, Service Pack 2) -- if the file is still mapped, the following
926 if (rp->re_smap != NULL) {
927 (void)__db_munmap(rp->re_smap, rp->re_msize);
931 /* Get rid of any backing file descriptor, just on GP's. */
932 if (rp->re_fd != -1) {
933 (void)__db_close(rp->re_fd);
937 /* Open the file, truncating it. */
938 if ((ret = __db_fdopen(rp->re_source,
939 DB_SEQUENTIAL | DB_TRUNCATE,
940 DB_SEQUENTIAL | DB_TRUNCATE, 0, &fd)) != 0) {
941 __db_err(dbp->dbenv, "%s: %s", rp->re_source, strerror(ret));
946 * We step through the records, writing each one out. Use the record
947 * number and the dbp->get() function, instead of a cursor, so we find
948 * and write out "deleted" or non-existent records.
950 memset(&key, 0, sizeof(key));
951 memset(&data, 0, sizeof(data));
952 key.size = sizeof(db_recno_t);
956 * We'll need the delimiter if we're doing variable-length records,
957 * and the pad character if we're doing fixed-length records.
959 delim = rp->re_delim;
960 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
961 if ((pad = malloc(rp->re_len)) == NULL) {
965 memset(pad, rp->re_pad, rp->re_len);
967 pad = NULL; /* XXX: Shut the compiler up. */
968 for (keyno = 1;; ++keyno) {
969 switch (ret = dbp->get(dbp, NULL, &key, &data, 0)) {
972 __db_write(fd, data.data, data.size, &nw)) != 0)
974 if (nw != (ssize_t)data.size) {
980 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
982 __db_write(fd, pad, rp->re_len, &nw)) != 0)
984 if (nw != (ssize_t)rp->re_len) {
994 if (!F_ISSET(dbp, DB_RE_FIXEDLEN)) {
995 if ((ret = __db_write(fd, &delim, 1, &nw)) != 0)
1005 done: /* Close the file descriptor. */
1006 if ((t_ret = __db_close(fd)) != 0 || ret == 0)
1010 F_CLR(rp, RECNO_MODIFIED);
1016 * Get fixed length records from a file.
1019 __ram_fmap(dbp, top)
1028 u_int8_t *sp, *ep, *p;
1031 if ((ret = __bam_nrecs(dbp, &recno)) != 0)
1036 if (t->bt_rdata.ulen < rp->re_len) {
1037 t->bt_rdata.data = t->bt_rdata.data == NULL ?
1038 (void *)malloc(rp->re_len) :
1039 (void *)realloc(t->bt_rdata.data, rp->re_len);
1040 if (t->bt_rdata.data == NULL) {
1041 t->bt_rdata.ulen = 0;
1044 t->bt_rdata.ulen = rp->re_len;
1047 memset(&data, 0, sizeof(data));
1048 data.data = t->bt_rdata.data;
1049 data.size = rp->re_len;
1051 sp = (u_int8_t *)rp->re_cmap;
1052 ep = (u_int8_t *)rp->re_emap;
1053 while (recno <= top) {
1055 F_SET(rp, RECNO_EOF);
1056 return (DB_NOTFOUND);
1059 for (p = t->bt_rdata.data;
1060 sp < ep && len > 0; *p++ = *sp++, --len);
1063 * Another process may have read some portion of the input
1064 * file already, in which case we just want to discard the
1068 * We should just do a seek, since the records are fixed
1071 if (rp->re_last >= recno) {
1073 memset(p, rp->re_pad, len);
1076 if ((ret = __ram_add(dbp, &recno, &data, 0, 0)) != 0)
1087 * Get variable length records from a file.
1090 __ram_vmap(dbp, top)
1104 if ((ret = __bam_nrecs(dbp, &recno)) != 0)
1107 memset(&data, 0, sizeof(data));
1109 delim = rp->re_delim;
1111 sp = (u_int8_t *)rp->re_cmap;
1112 ep = (u_int8_t *)rp->re_emap;
1113 while (recno <= top) {
1115 F_SET(rp, RECNO_EOF);
1116 return (DB_NOTFOUND);
1118 for (data.data = sp; sp < ep && *sp != delim; ++sp);
1121 * Another process may have read some portion of the input
1122 * file already, in which case we just want to discard the
1125 if (rp->re_last >= recno) {
1126 data.size = sp - (u_int8_t *)data.data;
1128 if ((ret = __ram_add(dbp, &recno, &data, 0, 0)) != 0)
1140 * Add records into the tree.
1143 __ram_add(dbp, recnop, data, flags, bi_flags)
1147 int flags, bi_flags;
1152 int exact, ret, stack;
1156 retry: /* Find the slot for insertion. */
1157 if ((ret = __bam_rsearch(dbp, recnop,
1158 S_INSERT | (LF_ISSET(DB_APPEND) ? S_APPEND : 0), 1, &exact)) != 0)
1160 h = t->bt_csp->page;
1161 indx = t->bt_csp->indx;
1165 * The recno access method doesn't currently support duplicates, so
1166 * if an identical key is already in the tree we're either overwriting
1167 * it or an error is returned.
1169 if (exact && LF_ISSET(DB_NOOVERWRITE)) {
1175 * Select the arguments for __bam_iitem() and do the insert. If the
1176 * key is an exact match, or we're replacing the data item with a
1177 * new data item. If the key isn't an exact match, we're inserting
1178 * a new key/data pair, before the search location.
1180 if ((ret = __bam_iitem(dbp, &h, &indx, NULL,
1181 data, exact ? DB_CURRENT : DB_BEFORE, bi_flags)) == DB_NEEDSPLIT) {
1182 (void)__bam_stkrel(dbp);
1184 if ((ret = __bam_split(dbp, recnop)) != 0)
1189 if (!exact && ret == 0)
1190 __bam_adjust(dbp, t, 1);