2 * See the file LICENSE for redistribution information.
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid[] = "@(#)bt_recno.c 10.19 (Sleepycat) 9/20/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 != NULL && 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;
197 * All cursors are queued from the master DB structure. Add the
198 * cursor to that queue.
201 TAILQ_INSERT_HEAD(&dbp->curs_queue, dbc, links);
202 DB_THREAD_UNLOCK(dbp);
210 * Recno db->get function.
213 __ram_get(argdbp, txn, key, data, flags)
224 int exact, ret, stack;
228 DEBUG_LWRITE(argdbp, txn, "ram_get", key, NULL, flags);
230 /* Check for invalid flags. */
231 if ((ret = __db_getchk(argdbp, key, data, flags)) != 0)
234 GETHANDLE(argdbp, txn, &dbp, ret);
237 /* Check the user's record number and fill in as necessary. */
238 if ((ret = __ram_getno(dbp, key, &recno, 0)) != 0)
241 /* Search the tree for the record. */
242 if ((ret = __bam_rsearch(dbp, &recno, S_FIND, 1, &exact)) != 0)
245 return (DB_NOTFOUND);
249 indx = t->bt_csp->indx;
251 /* If the record has already been deleted, we couldn't have found it. */
252 if (B_DISSET(GET_BKEYDATA(h, indx)->type)) {
257 /* Return the data item. */
259 h, indx, data, &t->bt_rdata.data, &t->bt_rdata.ulen);
262 done: /* Discard the stack. */
272 * Recno db->put function.
275 __ram_put(argdbp, txn, key, data, flags)
286 DEBUG_LWRITE(argdbp, txn, "ram_put", key, data, flags);
288 /* Check for invalid flags. */
289 if ((ret = __db_putchk(argdbp,
290 key, data, flags, F_ISSET(argdbp, DB_AM_RDONLY), 0)) != 0)
293 GETHANDLE(argdbp, txn, &dbp, ret);
296 * If we're appending to the tree, make sure we've read in all of
297 * the backing source file. Otherwise, check the user's record
298 * number and fill in as necessary.
300 ret = LF_ISSET(DB_APPEND) ?
301 __ram_snapshot(dbp) : __ram_getno(dbp, key, &recno, 1);
303 /* Add the record. */
305 ret = __ram_add(dbp, &recno, data, flags, 0);
307 /* If we're appending to the tree, we have to return the record. */
308 if (ret == 0 && LF_ISSET(DB_APPEND)) {
310 ret = __db_retcopy(key, &recno, sizeof(recno),
311 &t->bt_rkey.data, &t->bt_rkey.ulen, dbp->db_malloc);
320 * Recno db->sync function.
323 __ram_sync(argdbp, flags)
330 DEBUG_LWRITE(argdbp, NULL, "ram_sync", NULL, NULL, flags);
332 /* Sync the underlying btree. */
333 if ((ret = __bam_sync(argdbp, flags)) != 0)
336 /* Copy back the backing source file. */
337 GETHANDLE(argdbp, NULL, &dbp, ret);
338 ret = __ram_writeback(dbp);
346 * Recno db->close function.
348 * PUBLIC: int __ram_close __P((DB *));
356 DEBUG_LWRITE(argdbp, NULL, "ram_close", NULL, NULL, 0);
358 rp = ((BTREE *)argdbp->internal)->bt_recno;
360 /* Close any underlying mmap region. */
361 if (rp->re_smap != NULL)
362 (void)__db_munmap(rp->re_smap, rp->re_msize);
364 /* Close any backing source file descriptor. */
366 (void)__db_close(rp->re_fd);
368 /* Free any backing source file name. */
369 if (rp->re_source != NULL)
370 FREES(rp->re_source);
372 /* Free allocated memory. */
373 FREE(rp, sizeof(RECNO));
374 ((BTREE *)argdbp->internal)->bt_recno = NULL;
376 /* Close the underlying btree. */
377 return (__bam_close(argdbp));
382 * Recno cursor->close function.
388 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_close", NULL, NULL, 0);
390 return (__ram_c_iclose(dbc->dbp, dbc));
395 * Close a single cursor -- internal version.
397 * PUBLIC: int __ram_c_iclose __P((DB *, DBC *));
400 __ram_c_iclose(dbp, dbc)
405 * All cursors are queued from the master DB structure. Remove the
406 * cursor from that queue.
408 DB_THREAD_LOCK(dbc->dbp);
409 TAILQ_REMOVE(&dbc->dbp->curs_queue, dbc, links);
410 DB_THREAD_UNLOCK(dbc->dbp);
412 /* Discard the structures. */
413 FREE(dbc->internal, sizeof(RCURSOR));
414 FREE(dbc, sizeof(DBC));
421 * Recno cursor->c_del function.
424 __ram_c_del(dbc, flags)
432 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_del", NULL, NULL, flags);
436 /* Check for invalid flags. */
437 if ((ret = __db_cdelchk(dbc->dbp, flags,
438 F_ISSET(dbc->dbp, DB_AM_RDONLY), cp->recno != RECNO_OOB)) != 0)
441 /* If already deleted, return failure. */
442 if (CD_ISSET(dbc->dbp, cp))
443 return (DB_KEYEMPTY);
445 /* Build a normal delete request. */
446 memset(&key, 0, sizeof(key));
447 key.data = &cp->recno;
448 key.size = sizeof(db_recno_t);
449 if ((ret = __ram_delete(dbc->dbp, dbc->txn, &key, 0)) == 0)
450 CD_SET(dbc->dbp, cp);
457 * Recno cursor->c_get function.
460 __ram_c_get(dbc, key, data, flags)
470 DEBUG_LREAD(dbc->dbp, dbc->txn, "ram_c_get",
471 flags == DB_SET || flags == DB_SET_RANGE ? key : NULL,
477 /* Check for invalid flags. */
478 if ((ret = __db_cgetchk(dbc->dbp,
479 key, data, flags, cp->recno != RECNO_OOB)) != 0)
482 GETHANDLE(dbc->dbp, dbc->txn, &dbp, ret);
485 /* Initialize the cursor for a new retrieval. */
488 retry: /* Update the record number. */
491 if (CD_ISSET(dbp, cp)) {
493 return (DB_KEYEMPTY);
497 if (CD_ISSET(dbp, cp))
499 if (cp->recno != RECNO_OOB) {
509 if (cp->recno != RECNO_OOB) {
511 return (DB_NOTFOUND);
518 if (((ret = __ram_snapshot(dbp)) != 0) && ret != DB_NOTFOUND)
520 if ((ret = __bam_nrecs(dbp, &cp->recno)) != 0)
523 return (DB_NOTFOUND);
527 if ((ret = __ram_getno(dbp, key, &cp->recno, 0)) != 0)
533 * Return the key if the user didn't give us one, and then pass it
536 if (flags != DB_SET && flags != DB_SET_RANGE &&
537 (ret = __db_retcopy(key, &cp->recno, sizeof(cp->recno),
538 &t->bt_rkey.data, &t->bt_rkey.ulen, dbp->db_malloc)) != 0)
542 * The cursor was reset, so the delete adjustment is no
548 * Retrieve the record.
550 * Skip any keys that don't really exist.
552 if ((ret = __ram_get(dbp, dbc->txn, key, data, 0)) != 0)
553 if (ret == DB_KEYEMPTY &&
554 (flags == DB_NEXT || flags == DB_PREV))
566 * Recno cursor->c_put function.
569 __ram_c_put(dbc, key, data, flags)
580 DEBUG_LWRITE(dbc->dbp, dbc->txn, "ram_c_put", NULL, data, flags);
584 if ((ret = __db_cputchk(dbc->dbp, key, data, flags,
585 F_ISSET(dbc->dbp, DB_AM_RDONLY), cp->recno != RECNO_OOB)) != 0)
588 GETHANDLE(dbc->dbp, dbc->txn, &dbp, ret);
591 /* Initialize the cursor for a new retrieval. */
595 * To split, we need a valid key for the page. Since it's a cursor,
596 * we have to build one.
598 * The split code discards all short-term locks and stack pages.
601 split: arg = &cp->recno;
602 if ((ret = __bam_split(dbp, arg)) != 0)
606 if ((ret = __bam_rsearch(dbp, &cp->recno, S_INSERT, 1, &exact)) != 0)
612 if ((ret = __bam_iitem(dbp, &t->bt_csp->page,
613 &t->bt_csp->indx, key, data, flags, 0)) == DB_NEEDSPLIT) {
614 if ((ret = __bam_stkrel(dbp)) != 0)
618 if ((ret = __bam_stkrel(dbp)) != 0)
621 if (flags != DB_CURRENT) {
622 /* Adjust the counts. */
623 if ((ret = __bam_adjust(dbp, t, 1)) != 0)
628 /* Adjust the cursors. */
629 __ram_ca(dbp, cp->recno, CA_IAFTER);
631 /* Set this cursor to reference the new record. */
632 cp->recno = copy.recno + 1;
635 /* Adjust the cursors. */
636 __ram_ca(dbp, cp->recno, CA_IBEFORE);
638 /* Set this cursor to reference the new record. */
639 cp->recno = copy.recno;
646 * The cursor was reset, so the delete adjustment is no
662 * PUBLIC: void __ram_ca __P((DB *, db_recno_t, ca_recno_arg));
665 __ram_ca(dbp, recno, op)
674 * Adjust the cursors. See the comment in __bam_ca_delete().
677 for (dbc = TAILQ_FIRST(&dbp->curs_queue);
678 dbc != NULL; dbc = TAILQ_NEXT(dbc, links)) {
679 cp = (RCURSOR *)dbc->internal;
682 if (recno > cp->recno)
686 if (recno > cp->recno)
690 if (recno >= cp->recno)
695 DB_THREAD_UNLOCK(dbp);
701 * Display the current recno cursor list.
711 for (dbc = TAILQ_FIRST(&dbp->curs_queue);
712 dbc != NULL; dbc = TAILQ_NEXT(dbc, links)) {
713 cp = (RCURSOR *)dbc->internal;
715 "%#0x: recno: %lu\n", (u_int)cp, (u_long)cp->recno);
717 DB_THREAD_UNLOCK(dbp);
724 * Check the user's record number, and make sure we've seen it.
726 * PUBLIC: int __ram_getno __P((DB *, const DBT *, db_recno_t *, int));
729 __ram_getno(dbp, key, rep, can_create)
737 /* Check the user's record number. */
738 if ((recno = *(db_recno_t *)key->data) == 0) {
739 __db_err(dbp->dbenv, "illegal record number of 0");
746 * Btree can neither create records or read them in. Recno can
747 * do both, see if we can find the record.
749 return (dbp->type == DB_RECNO ?
750 __ram_update(dbp, recno, can_create) : 0);
755 * Read in any remaining records from the backing input file.
757 * PUBLIC: int __ram_snapshot __P((DB *));
763 return (__ram_update(dbp, DB_MAX_RECORDS, 0));
768 * Ensure the tree has records up to and including the specified one.
771 __ram_update(dbp, recno, can_create)
785 * If we can't create records and we've read the entire backing input
788 if (!can_create && F_ISSET(rp, RECNO_EOF))
792 * If we haven't seen this record yet, try to get it from the original
795 if ((ret = __bam_nrecs(dbp, &nrecs)) != 0)
797 if (!F_ISSET(rp, RECNO_EOF) && recno > nrecs) {
798 if ((ret = rp->re_irec(dbp, recno)) != 0)
800 if ((ret = __bam_nrecs(dbp, &nrecs)) != 0)
805 * If we can create records, create empty ones up to the requested
808 if (!can_create || recno <= nrecs + 1)
811 t->bt_rdata.dlen = 0;
812 t->bt_rdata.doff = 0;
813 t->bt_rdata.flags = 0;
814 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
815 if (t->bt_rdata.ulen < rp->re_len) {
816 t->bt_rdata.data = t->bt_rdata.data == NULL ?
817 (void *)malloc(rp->re_len) :
818 (void *)realloc(t->bt_rdata.data, rp->re_len);
819 if (t->bt_rdata.data == NULL) {
820 t->bt_rdata.ulen = 0;
823 t->bt_rdata.ulen = rp->re_len;
825 t->bt_rdata.size = rp->re_len;
826 memset(t->bt_rdata.data, rp->re_pad, rp->re_len);
828 t->bt_rdata.size = 0;
830 while (recno > ++nrecs)
831 if ((ret = __ram_add(dbp,
832 &nrecs, &t->bt_rdata, 0, BI_DELETED)) != 0)
839 * Load information about the backing file.
842 __ram_source(dbp, rp, fname)
850 if ((ret = __db_appname(dbp->dbenv,
851 DB_APP_DATA, NULL, fname, NULL, &rp->re_source)) != 0)
854 oflags = F_ISSET(dbp, DB_AM_RDONLY) ? DB_RDONLY : 0;
856 __db_fdopen(rp->re_source, oflags, oflags, 0, &rp->re_fd)) != 0) {
857 __db_err(dbp->dbenv, "%s: %s", rp->re_source, strerror(ret));
863 * We'd like to test to see if the file is too big to mmap. Since we
864 * don't know what size or type off_t's or size_t's are, or the largest
865 * unsigned integral type is, or what random insanity the local C
866 * compiler will perpetrate, doing the comparison in a portable way is
867 * flatly impossible. Hope that mmap fails if the file is too large.
870 __db_stat(dbp->dbenv, rp->re_source, rp->re_fd, &size, NULL)) != 0)
873 F_SET(rp, RECNO_EOF);
877 if ((ret = __db_mmap(rp->re_fd, (size_t)size, 1, 1, &rp->re_smap)) != 0)
879 rp->re_cmap = rp->re_smap;
880 rp->re_emap = (u_int8_t *)rp->re_smap + (rp->re_msize = size);
881 rp->re_irec = F_ISSET(dbp, DB_RE_FIXEDLEN) ? __ram_fmap : __ram_vmap;
884 err: FREES(rp->re_source)
890 * Rewrite the backing file.
901 u_int8_t delim, *pad;
903 rp = ((BTREE *)dbp->internal)->bt_recno;
905 /* If the file wasn't modified, we're done. */
906 if (!F_ISSET(rp, RECNO_MODIFIED))
909 /* If there's no backing source file, we're done. */
910 if (rp->re_source == NULL) {
911 F_CLR(rp, RECNO_MODIFIED);
916 * Read any remaining records into the tree.
919 * This is why we can't support transactions when applications specify
920 * backing (re_source) files. At this point we have to read in the
921 * rest of the records from the file so that we can write all of the
922 * records back out again, which could modify a page for which we'd
923 * have to log changes and which we don't have locked. This could be
924 * partially fixed by taking a snapshot of the entire file during the
925 * db_open(), or, since db_open() isn't transaction protected, as part
926 * of the first DB operation. But, if a checkpoint occurs then, the
927 * part of the log holding the copy of the file could be discarded, and
928 * that would make it impossible to recover in the face of disaster.
929 * This could all probably be fixed, but it would require transaction
930 * protecting the backing source file, i.e. mpool would have to know
931 * about it, and we don't want to go there.
933 if ((ret = __ram_snapshot(dbp)) != 0 && ret != DB_NOTFOUND)
938 * Close any underlying mmap region. This is required for Windows NT
939 * (4.0, Service Pack 2) -- if the file is still mapped, the following
942 if (rp->re_smap != NULL) {
943 (void)__db_munmap(rp->re_smap, rp->re_msize);
947 /* Get rid of any backing file descriptor, just on GP's. */
948 if (rp->re_fd != -1) {
949 (void)__db_close(rp->re_fd);
953 /* Open the file, truncating it. */
954 if ((ret = __db_fdopen(rp->re_source,
955 DB_SEQUENTIAL | DB_TRUNCATE,
956 DB_SEQUENTIAL | DB_TRUNCATE, 0, &fd)) != 0) {
957 __db_err(dbp->dbenv, "%s: %s", rp->re_source, strerror(ret));
962 * We step through the records, writing each one out. Use the record
963 * number and the dbp->get() function, instead of a cursor, so we find
964 * and write out "deleted" or non-existent records.
966 memset(&key, 0, sizeof(key));
967 memset(&data, 0, sizeof(data));
968 key.size = sizeof(db_recno_t);
972 * We'll need the delimiter if we're doing variable-length records,
973 * and the pad character if we're doing fixed-length records.
975 delim = rp->re_delim;
976 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
977 if ((pad = malloc(rp->re_len)) == NULL) {
981 memset(pad, rp->re_pad, rp->re_len);
983 pad = NULL; /* XXX: Shut the compiler up. */
984 for (keyno = 1;; ++keyno) {
985 switch (ret = dbp->get(dbp, NULL, &key, &data, 0)) {
988 __db_write(fd, data.data, data.size, &nw)) != 0)
990 if (nw != (ssize_t)data.size) {
996 if (F_ISSET(dbp, DB_RE_FIXEDLEN)) {
998 __db_write(fd, pad, rp->re_len, &nw)) != 0)
1000 if (nw != (ssize_t)rp->re_len) {
1010 if (!F_ISSET(dbp, DB_RE_FIXEDLEN)) {
1011 if ((ret = __db_write(fd, &delim, 1, &nw)) != 0)
1021 done: /* Close the file descriptor. */
1022 if ((t_ret = __db_close(fd)) != 0 || ret == 0)
1026 F_CLR(rp, RECNO_MODIFIED);
1032 * Get fixed length records from a file.
1035 __ram_fmap(dbp, top)
1044 u_int8_t *sp, *ep, *p;
1047 if ((ret = __bam_nrecs(dbp, &recno)) != 0)
1052 if (t->bt_rdata.ulen < rp->re_len) {
1053 t->bt_rdata.data = t->bt_rdata.data == NULL ?
1054 (void *)malloc(rp->re_len) :
1055 (void *)realloc(t->bt_rdata.data, rp->re_len);
1056 if (t->bt_rdata.data == NULL) {
1057 t->bt_rdata.ulen = 0;
1060 t->bt_rdata.ulen = rp->re_len;
1063 memset(&data, 0, sizeof(data));
1064 data.data = t->bt_rdata.data;
1065 data.size = rp->re_len;
1067 sp = (u_int8_t *)rp->re_cmap;
1068 ep = (u_int8_t *)rp->re_emap;
1069 while (recno <= top) {
1071 F_SET(rp, RECNO_EOF);
1072 return (DB_NOTFOUND);
1075 for (p = t->bt_rdata.data;
1076 sp < ep && len > 0; *p++ = *sp++, --len);
1079 * Another process may have read some portion of the input
1080 * file already, in which case we just want to discard the
1084 * We should just do a seek, since the records are fixed
1087 if (rp->re_last >= recno) {
1089 memset(p, rp->re_pad, len);
1092 if ((ret = __ram_add(dbp, &recno, &data, 0, 0)) != 0)
1103 * Get variable length records from a file.
1106 __ram_vmap(dbp, top)
1120 if ((ret = __bam_nrecs(dbp, &recno)) != 0)
1123 memset(&data, 0, sizeof(data));
1125 delim = rp->re_delim;
1127 sp = (u_int8_t *)rp->re_cmap;
1128 ep = (u_int8_t *)rp->re_emap;
1129 while (recno <= top) {
1131 F_SET(rp, RECNO_EOF);
1132 return (DB_NOTFOUND);
1134 for (data.data = sp; sp < ep && *sp != delim; ++sp);
1137 * Another process may have read some portion of the input
1138 * file already, in which case we just want to discard the
1141 if (rp->re_last >= recno) {
1142 data.size = sp - (u_int8_t *)data.data;
1144 if ((ret = __ram_add(dbp, &recno, &data, 0, 0)) != 0)
1156 * Add records into the tree.
1159 __ram_add(dbp, recnop, data, flags, bi_flags)
1163 int flags, bi_flags;
1168 int exact, ret, stack;
1172 retry: /* Find the slot for insertion. */
1173 if ((ret = __bam_rsearch(dbp, recnop,
1174 S_INSERT | (LF_ISSET(DB_APPEND) ? S_APPEND : 0), 1, &exact)) != 0)
1176 h = t->bt_csp->page;
1177 indx = t->bt_csp->indx;
1181 * The recno access method doesn't currently support duplicates, so
1182 * if an identical key is already in the tree we're either overwriting
1183 * it or an error is returned.
1185 if (exact && LF_ISSET(DB_NOOVERWRITE)) {
1191 * Select the arguments for __bam_iitem() and do the insert. If the
1192 * key is an exact match, or we're replacing the data item with a
1193 * new data item. If the key isn't an exact match, we're inserting
1194 * a new key/data pair, before the search location.
1196 if ((ret = __bam_iitem(dbp, &h, &indx, NULL,
1197 data, exact ? DB_CURRENT : DB_BEFORE, bi_flags)) == DB_NEEDSPLIT) {
1198 (void)__bam_stkrel(dbp);
1200 if ((ret = __bam_split(dbp, recnop)) != 0)
1205 if (!exact && ret == 0)
1206 __bam_adjust(dbp, t, 1);