summaryrefslogtreecommitdiff
path: root/bdb/qam
diff options
context:
space:
mode:
authorunknown <ram@mysql.r18.ru>2002-10-30 15:57:05 +0400
committerunknown <ram@mysql.r18.ru>2002-10-30 15:57:05 +0400
commit155e78f014de1a2e259ae5119f4621fbb210a784 (patch)
tree6881a3cca88bea0bb9eeffd5aae34be437152786 /bdb/qam
parentb8798d25ab71436bf690ee8ae48285a655c5487e (diff)
downloadmariadb-git-155e78f014de1a2e259ae5119f4621fbb210a784.tar.gz
BDB 4.1.24
BitKeeper/deleted/.del-ex_access.wpj~3df6ae8c99bf7c5f: Delete: bdb/build_vxworks/ex_access/ex_access.wpj BitKeeper/deleted/.del-ex_btrec.wpj~a7622f1c6f432dc6: Delete: bdb/build_vxworks/ex_btrec/ex_btrec.wpj BitKeeper/deleted/.del-ex_dbclient.wpj~7345440f3b204cdd: Delete: bdb/build_vxworks/ex_dbclient/ex_dbclient.wpj BitKeeper/deleted/.del-ex_env.wpj~fbe1ab10b04e8b74: Delete: bdb/build_vxworks/ex_env/ex_env.wpj BitKeeper/deleted/.del-ex_mpool.wpj~4479cfd5c45f327d: Delete: bdb/build_vxworks/ex_mpool/ex_mpool.wpj BitKeeper/deleted/.del-ex_tpcb.wpj~f78093006e14bf41: Delete: bdb/build_vxworks/ex_tpcb/ex_tpcb.wpj BitKeeper/deleted/.del-db_buildall.dsp~bd749ff6da11682: Delete: bdb/build_win32/db_buildall.dsp BitKeeper/deleted/.del-cxx_app.cpp~ad8df8e0791011ed: Delete: bdb/cxx/cxx_app.cpp BitKeeper/deleted/.del-cxx_log.cpp~a50ff3118fe06952: Delete: bdb/cxx/cxx_log.cpp BitKeeper/deleted/.del-cxx_table.cpp~ecd751e79b055556: Delete: bdb/cxx/cxx_table.cpp BitKeeper/deleted/.del-namemap.txt~796a3acd3885d8fd: Delete: bdb/cxx/namemap.txt BitKeeper/deleted/.del-Design.fileop~3ca4da68f1727373: Delete: bdb/db/Design.fileop BitKeeper/deleted/.del-db185_int.h~61bee3736e7959ef: Delete: bdb/db185/db185_int.h BitKeeper/deleted/.del-acconfig.h~411e8854d67ad8b5: Delete: bdb/dist/acconfig.h BitKeeper/deleted/.del-mutex.m4~a13383cde18a64e1: Delete: bdb/dist/aclocal/mutex.m4 BitKeeper/deleted/.del-options.m4~b9d0ca637213750a: Delete: bdb/dist/aclocal/options.m4 BitKeeper/deleted/.del-programs.m4~3ce7890b47732b30: Delete: bdb/dist/aclocal/programs.m4 BitKeeper/deleted/.del-tcl.m4~f944e2db93c3b6db: Delete: bdb/dist/aclocal/tcl.m4 BitKeeper/deleted/.del-types.m4~59cae158c9a32cff: Delete: bdb/dist/aclocal/types.m4 BitKeeper/deleted/.del-script~d38f6d3a4f159cb4: Delete: bdb/dist/build/script BitKeeper/deleted/.del-configure.in~ac795a92c8fe049c: Delete: bdb/dist/configure.in BitKeeper/deleted/.del-ltconfig~66bbd007d8024af: Delete: bdb/dist/ltconfig BitKeeper/deleted/.del-rec_ctemp~a28554362534f00a: Delete: bdb/dist/rec_ctemp BitKeeper/deleted/.del-s_tcl~2ffe4326459fcd9f: Delete: bdb/dist/s_tcl BitKeeper/deleted/.del-.IGNORE_ME~d8148b08fa7d5d15: Delete: bdb/dist/template/.IGNORE_ME BitKeeper/deleted/.del-btree.h~179f2aefec1753d: Delete: bdb/include/btree.h BitKeeper/deleted/.del-cxx_int.h~6b649c04766508f8: Delete: bdb/include/cxx_int.h BitKeeper/deleted/.del-db.src~6b433ae615b16a8d: Delete: bdb/include/db.src BitKeeper/deleted/.del-db_185.h~ad8b373d9391d35c: Delete: bdb/include/db_185.h BitKeeper/deleted/.del-db_am.h~a714912b6b75932f: Delete: bdb/include/db_am.h BitKeeper/deleted/.del-db_cxx.h~fcafadf45f5d19e9: Delete: bdb/include/db_cxx.h BitKeeper/deleted/.del-db_dispatch.h~6844f20f7eb46904: Delete: bdb/include/db_dispatch.h BitKeeper/deleted/.del-db_int.src~419a3f48b6a01da7: Delete: bdb/include/db_int.src BitKeeper/deleted/.del-db_join.h~76f9747a42c3399a: Delete: bdb/include/db_join.h BitKeeper/deleted/.del-db_page.h~e302ca3a4db3abdc: Delete: bdb/include/db_page.h BitKeeper/deleted/.del-db_server_int.h~e1d20b6ba3bca1ab: Delete: bdb/include/db_server_int.h BitKeeper/deleted/.del-db_shash.h~5fbf2d696fac90f3: Delete: bdb/include/db_shash.h BitKeeper/deleted/.del-db_swap.h~1e60887550864a59: Delete: bdb/include/db_swap.h BitKeeper/deleted/.del-db_upgrade.h~c644eee73701fc8d: Delete: bdb/include/db_upgrade.h BitKeeper/deleted/.del-db_verify.h~b8d6c297c61f342e: Delete: bdb/include/db_verify.h BitKeeper/deleted/.del-debug.h~dc2b4f2cf27ccebc: Delete: bdb/include/debug.h BitKeeper/deleted/.del-hash.h~2aaa548b28882dfb: Delete: bdb/include/hash.h BitKeeper/deleted/.del-lock.h~a761c1b7de57b77f: Delete: bdb/include/lock.h BitKeeper/deleted/.del-log.h~ff20184238e35e4d: Delete: bdb/include/log.h BitKeeper/deleted/.del-mp.h~7e317597622f3411: Delete: bdb/include/mp.h BitKeeper/deleted/.del-mutex.h~d3ae7a2977a68137: Delete: bdb/include/mutex.h BitKeeper/deleted/.del-os.h~91867cc8757cd0e3: Delete: bdb/include/os.h BitKeeper/deleted/.del-os_jump.h~e1b939fa5151d4be: Delete: bdb/include/os_jump.h BitKeeper/deleted/.del-qam.h~6fad0c1b5723d597: Delete: bdb/include/qam.h BitKeeper/deleted/.del-queue.h~4c72c0826c123d5: Delete: bdb/include/queue.h BitKeeper/deleted/.del-region.h~513fe04d977ca0fc: Delete: bdb/include/region.h BitKeeper/deleted/.del-shqueue.h~525fc3e6c2025c36: Delete: bdb/include/shqueue.h BitKeeper/deleted/.del-tcl_db.h~c536fd61a844f23f: Delete: bdb/include/tcl_db.h BitKeeper/deleted/.del-txn.h~c8d94b221ec147e4: Delete: bdb/include/txn.h BitKeeper/deleted/.del-xa.h~ecc466493aae9d9a: Delete: bdb/include/xa.h BitKeeper/deleted/.del-DbRecoveryInit.java~756b52601a0b9023: Delete: bdb/java/src/com/sleepycat/db/DbRecoveryInit.java BitKeeper/deleted/.del-DbTxnRecover.java~74607cba7ab89d6d: Delete: bdb/java/src/com/sleepycat/db/DbTxnRecover.java BitKeeper/deleted/.del-lock_conflict.c~fc5e0f14cf597a2b: Delete: bdb/lock/lock_conflict.c BitKeeper/deleted/.del-log.src~53ac9e7b5cb023f2: Delete: bdb/log/log.src BitKeeper/deleted/.del-log_findckp.c~24287f008916e81f: Delete: bdb/log/log_findckp.c BitKeeper/deleted/.del-log_rec.c~d51711f2cac09297: Delete: bdb/log/log_rec.c BitKeeper/deleted/.del-log_register.c~b40bb4efac75ca15: Delete: bdb/log/log_register.c BitKeeper/deleted/.del-Design~b3d0f179f2767b: Delete: bdb/mp/Design BitKeeper/deleted/.del-os_finit.c~95dbefc6fe79b26c: Delete: bdb/os/os_finit.c BitKeeper/deleted/.del-os_abs.c~df95d1e7db81924: Delete: bdb/os_vxworks/os_abs.c BitKeeper/deleted/.del-os_finit.c~803b484bdb9d0122: Delete: bdb/os_vxworks/os_finit.c BitKeeper/deleted/.del-os_map.c~3a6d7926398b76d3: Delete: bdb/os_vxworks/os_map.c BitKeeper/deleted/.del-os_finit.c~19a227c6d3c78ad: Delete: bdb/os_win32/os_finit.c BitKeeper/deleted/.del-log-corruption.patch~1cf2ecc7c6408d5d: Delete: bdb/patches/log-corruption.patch BitKeeper/deleted/.del-Btree.pm~af6d0c5eaed4a98e: Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Btree.pm BitKeeper/deleted/.del-BerkeleyDB.pm~7244036d4482643: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pm BitKeeper/deleted/.del-BerkeleyDB.pod~e7b18fd6132448e3: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod BitKeeper/deleted/.del-Hash.pm~10292a26c06a5c95: Delete: bdb/perl.BerkeleyDB/BerkeleyDB/Hash.pm BitKeeper/deleted/.del-BerkeleyDB.pod.P~79f76a1495eda203: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.pod.P BitKeeper/deleted/.del-BerkeleyDB.xs~80c99afbd98e392c: Delete: bdb/perl.BerkeleyDB/BerkeleyDB.xs BitKeeper/deleted/.del-Changes~729c1891efa60de9: Delete: bdb/perl.BerkeleyDB/Changes BitKeeper/deleted/.del-MANIFEST~63a1e34aecf157a0: Delete: bdb/perl.BerkeleyDB/MANIFEST BitKeeper/deleted/.del-Makefile.PL~c68797707d8df87a: Delete: bdb/perl.BerkeleyDB/Makefile.PL BitKeeper/deleted/.del-README~5f2f579b1a241407: Delete: bdb/perl.BerkeleyDB/README BitKeeper/deleted/.del-Todo~dca3c66c193adda9: Delete: bdb/perl.BerkeleyDB/Todo BitKeeper/deleted/.del-config.in~ae81681e450e0999: Delete: bdb/perl.BerkeleyDB/config.in BitKeeper/deleted/.del-dbinfo~28ad67d83be4f68e: Delete: bdb/perl.BerkeleyDB/dbinfo BitKeeper/deleted/.del-mkconsts~543ab60669c7a04e: Delete: bdb/perl.BerkeleyDB/mkconsts BitKeeper/deleted/.del-mkpod~182c0ca54e439afb: Delete: bdb/perl.BerkeleyDB/mkpod BitKeeper/deleted/.del-5.004~e008cb5a48805543: Delete: bdb/perl.BerkeleyDB/patches/5.004 BitKeeper/deleted/.del-irix_6_5.pl~61662bb08afcdec8: Delete: bdb/perl.BerkeleyDB/hints/irix_6_5.pl BitKeeper/deleted/.del-solaris.pl~6771e7182394e152: Delete: bdb/perl.BerkeleyDB/hints/solaris.pl BitKeeper/deleted/.del-typemap~783b8f5295b05f3d: Delete: bdb/perl.BerkeleyDB/typemap BitKeeper/deleted/.del-5.004_01~6081ce2fff7b0bc: Delete: bdb/perl.BerkeleyDB/patches/5.004_01 BitKeeper/deleted/.del-5.004_02~87214eac35ad9e6: Delete: bdb/perl.BerkeleyDB/patches/5.004_02 BitKeeper/deleted/.del-5.004_03~9a672becec7cb40f: Delete: bdb/perl.BerkeleyDB/patches/5.004_03 BitKeeper/deleted/.del-5.004_04~e326cb51af09d154: Delete: bdb/perl.BerkeleyDB/patches/5.004_04 BitKeeper/deleted/.del-5.004_05~7ab457a1e41a92fe: Delete: bdb/perl.BerkeleyDB/patches/5.004_05 BitKeeper/deleted/.del-5.005~f9e2d59b5964cd4b: Delete: bdb/perl.BerkeleyDB/patches/5.005 BitKeeper/deleted/.del-5.005_01~3eb9fb7b5842ea8e: Delete: bdb/perl.BerkeleyDB/patches/5.005_01 BitKeeper/deleted/.del-5.005_02~67477ce0bef717cb: Delete: bdb/perl.BerkeleyDB/patches/5.005_02 BitKeeper/deleted/.del-5.005_03~c4c29a1fb21e290a: Delete: bdb/perl.BerkeleyDB/patches/5.005_03 BitKeeper/deleted/.del-5.6.0~e1fb9897d124ee22: Delete: bdb/perl.BerkeleyDB/patches/5.6.0 BitKeeper/deleted/.del-btree.t~e4a1a3c675ddc406: Delete: bdb/perl.BerkeleyDB/t/btree.t BitKeeper/deleted/.del-db-3.0.t~d2c60991d84558f2: Delete: bdb/perl.BerkeleyDB/t/db-3.0.t BitKeeper/deleted/.del-db-3.1.t~6ee88cd13f55e018: Delete: bdb/perl.BerkeleyDB/t/db-3.1.t BitKeeper/deleted/.del-db-3.2.t~f73b6461f98fd1cf: Delete: bdb/perl.BerkeleyDB/t/db-3.2.t BitKeeper/deleted/.del-destroy.t~cc6a2ae1980a2ecd: Delete: bdb/perl.BerkeleyDB/t/destroy.t BitKeeper/deleted/.del-env.t~a8604a4499c4bd07: Delete: bdb/perl.BerkeleyDB/t/env.t BitKeeper/deleted/.del-examples.t~2571b77c3cc75574: Delete: bdb/perl.BerkeleyDB/t/examples.t BitKeeper/deleted/.del-examples.t.T~8228bdd75ac78b88: Delete: bdb/perl.BerkeleyDB/t/examples.t.T BitKeeper/deleted/.del-examples3.t.T~66a186897a87026d: Delete: bdb/perl.BerkeleyDB/t/examples3.t.T BitKeeper/deleted/.del-examples3.t~fe3822ba2f2d7f83: Delete: bdb/perl.BerkeleyDB/t/examples3.t BitKeeper/deleted/.del-filter.t~f87b045c1b708637: Delete: bdb/perl.BerkeleyDB/t/filter.t BitKeeper/deleted/.del-hash.t~616bfb4d644de3a3: Delete: bdb/perl.BerkeleyDB/t/hash.t BitKeeper/deleted/.del-join.t~29fc39f74a83ca22: Delete: bdb/perl.BerkeleyDB/t/join.t BitKeeper/deleted/.del-mldbm.t~31f5015341eea040: Delete: bdb/perl.BerkeleyDB/t/mldbm.t BitKeeper/deleted/.del-queue.t~8f338034ce44a641: Delete: bdb/perl.BerkeleyDB/t/queue.t BitKeeper/deleted/.del-recno.t~d4ddbd3743add63e: Delete: bdb/perl.BerkeleyDB/t/recno.t BitKeeper/deleted/.del-strict.t~6885cdd2ea71ca2d: Delete: bdb/perl.BerkeleyDB/t/strict.t BitKeeper/deleted/.del-subdb.t~aab62a5d5864c603: Delete: bdb/perl.BerkeleyDB/t/subdb.t BitKeeper/deleted/.del-txn.t~65033b8558ae1216: Delete: bdb/perl.BerkeleyDB/t/txn.t BitKeeper/deleted/.del-unknown.t~f3710458682665e1: Delete: bdb/perl.BerkeleyDB/t/unknown.t BitKeeper/deleted/.del-Changes~436f74a5c414c65b: Delete: bdb/perl.DB_File/Changes BitKeeper/deleted/.del-DB_File.pm~ae0951c6c7665a82: Delete: bdb/perl.DB_File/DB_File.pm BitKeeper/deleted/.del-DB_File.xs~89e49a0b5556f1d8: Delete: bdb/perl.DB_File/DB_File.xs BitKeeper/deleted/.del-DB_File_BS~290fad5dbbb87069: Delete: bdb/perl.DB_File/DB_File_BS BitKeeper/deleted/.del-MANIFEST~90ee581572bdd4ac: Delete: bdb/perl.DB_File/MANIFEST BitKeeper/deleted/.del-Makefile.PL~ac0567bb5a377e38: Delete: bdb/perl.DB_File/Makefile.PL BitKeeper/deleted/.del-README~77e924a5a9bae6b3: Delete: bdb/perl.DB_File/README BitKeeper/deleted/.del-config.in~ab4c2792b86a810b: Delete: bdb/perl.DB_File/config.in BitKeeper/deleted/.del-dbinfo~461c43b30fab2cb: Delete: bdb/perl.DB_File/dbinfo BitKeeper/deleted/.del-dynixptx.pl~50dcddfae25d17e9: Delete: bdb/perl.DB_File/hints/dynixptx.pl BitKeeper/deleted/.del-typemap~55cffb3288a9e587: Delete: bdb/perl.DB_File/typemap BitKeeper/deleted/.del-version.c~a4df0e646f8b3975: Delete: bdb/perl.DB_File/version.c BitKeeper/deleted/.del-5.004_01~d6830d0082702af7: Delete: bdb/perl.DB_File/patches/5.004_01 BitKeeper/deleted/.del-5.004_02~78b082dc80c91031: Delete: bdb/perl.DB_File/patches/5.004_02 BitKeeper/deleted/.del-5.004~4411ec2e3c9e008b: Delete: bdb/perl.DB_File/patches/5.004 BitKeeper/deleted/.del-sco.pl~1e795fe14fe4dcfe: Delete: bdb/perl.DB_File/hints/sco.pl BitKeeper/deleted/.del-5.004_03~33f274648b160d95: Delete: bdb/perl.DB_File/patches/5.004_03 BitKeeper/deleted/.del-5.004_04~8f3d1b3cf18bb20a: Delete: bdb/perl.DB_File/patches/5.004_04 BitKeeper/deleted/.del-5.004_05~9c0f02e7331e142: Delete: bdb/perl.DB_File/patches/5.004_05 BitKeeper/deleted/.del-5.005~c2108cb2e3c8d951: Delete: bdb/perl.DB_File/patches/5.005 BitKeeper/deleted/.del-5.005_01~3b45e9673afc4cfa: Delete: bdb/perl.DB_File/patches/5.005_01 BitKeeper/deleted/.del-5.005_02~9fe5766bb02a4522: Delete: bdb/perl.DB_File/patches/5.005_02 BitKeeper/deleted/.del-5.005_03~ffa1c38c19ae72ea: Delete: bdb/perl.DB_File/patches/5.005_03 BitKeeper/deleted/.del-5.6.0~373be3a5ce47be85: Delete: bdb/perl.DB_File/patches/5.6.0 BitKeeper/deleted/.del-db-btree.t~3231595a1c241eb3: Delete: bdb/perl.DB_File/t/db-btree.t BitKeeper/deleted/.del-db-hash.t~7c4ad0c795c7fad2: Delete: bdb/perl.DB_File/t/db-hash.t BitKeeper/deleted/.del-db-recno.t~6c2d3d80b9ba4a50: Delete: bdb/perl.DB_File/t/db-recno.t BitKeeper/deleted/.del-db_server.sed~cdb00ebcd48a64e2: Delete: bdb/rpc_server/db_server.sed BitKeeper/deleted/.del-db_server_proc.c~d46c8f409c3747f4: Delete: bdb/rpc_server/db_server_proc.c BitKeeper/deleted/.del-db_server_svc.sed~3f5e59f334fa4607: Delete: bdb/rpc_server/db_server_svc.sed BitKeeper/deleted/.del-db_server_util.c~a809f3a4629acda: Delete: bdb/rpc_server/db_server_util.c BitKeeper/deleted/.del-log.tcl~ff1b41f1355b97d7: Delete: bdb/test/log.tcl BitKeeper/deleted/.del-mpool.tcl~b0df4dc1b04db26c: Delete: bdb/test/mpool.tcl BitKeeper/deleted/.del-mutex.tcl~52fd5c73a150565: Delete: bdb/test/mutex.tcl BitKeeper/deleted/.del-txn.tcl~c4ff071550b5446e: Delete: bdb/test/txn.tcl BitKeeper/deleted/.del-README~e800a12a5392010a: Delete: bdb/test/upgrade/README BitKeeper/deleted/.del-pack-2.6.6.pl~89d5076d758d3e98: Delete: bdb/test/upgrade/generate-2.X/pack-2.6.6.pl BitKeeper/deleted/.del-test-2.6.patch~4a52dc83d447547b: Delete: bdb/test/upgrade/generate-2.X/test-2.6.patch
Diffstat (limited to 'bdb/qam')
-rw-r--r--bdb/qam/qam.c1070
-rw-r--r--bdb/qam/qam.src71
-rw-r--r--bdb/qam/qam_conv.c15
-rw-r--r--bdb/qam/qam_files.c293
-rw-r--r--bdb/qam/qam_method.c381
-rw-r--r--bdb/qam/qam_open.c309
-rw-r--r--bdb/qam/qam_rec.c424
-rw-r--r--bdb/qam/qam_stat.c90
-rw-r--r--bdb/qam/qam_upgrade.c9
-rw-r--r--bdb/qam/qam_verify.c50
10 files changed, 1466 insertions, 1246 deletions
diff --git a/bdb/qam/qam.c b/bdb/qam/qam.c
index 0c9f453044f..b10f8743439 100644
--- a/bdb/qam/qam.c
+++ b/bdb/qam/qam.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam.c,v 11.72 2001/01/16 20:10:55 ubell Exp $";
+static const char revid[] = "$Id: qam.c,v 11.134 2002/08/13 20:46:08 ubell Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,20 +18,20 @@ static const char revid[] = "$Id: qam.c,v 11.72 2001/01/16 20:10:55 ubell Exp $"
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_shash.h"
-#include "db_am.h"
-#include "mp.h"
-#include "lock.h"
-#include "log.h"
-#include "btree.h"
-#include "qam.h"
-
+#include "dbinc/db_page.h"
+#include "dbinc/db_shash.h"
+#include "dbinc/btree.h"
+#include "dbinc/lock.h"
+#include "dbinc/log.h"
+#include "dbinc/qam.h"
+
+static int __qam_bulk __P((DBC *, DBT *, u_int32_t));
static int __qam_c_close __P((DBC *, db_pgno_t, int *));
static int __qam_c_del __P((DBC *));
static int __qam_c_destroy __P((DBC *));
static int __qam_c_get __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
static int __qam_c_put __P((DBC *, DBT *, DBT *, u_int32_t, db_pgno_t *));
+static int __qam_consume __P((DBC *, QMETA *, db_recno_t));
static int __qam_getno __P((DB *, const DBT *, db_recno_t *));
/*
@@ -61,17 +61,16 @@ __qam_position(dbc, recnop, mode, exactp)
pg = QAM_RECNO_PAGE(dbp, *recnop);
if ((ret = __db_lget(dbc, 0, pg, mode == QAM_READ ?
- DB_LOCK_READ : DB_LOCK_WRITE, 0, &cp->lock)) != 0)
+ DB_LOCK_READ : DB_LOCK_WRITE, 0, &cp->lock)) != 0)
return (ret);
cp->page = NULL;
*exactp = 0;
if ((ret = __qam_fget(dbp, &pg,
- mode == QAM_WRITE ? DB_MPOOL_CREATE : 0,
- &cp->page)) != 0) {
+ mode == QAM_WRITE ? DB_MPOOL_CREATE : 0, &cp->page)) != 0) {
/* We did not fetch it, we can release the lock. */
(void)__LPUT(dbc, cp->lock);
- cp->lock.off = LOCK_INVALID;
- if (mode != QAM_WRITE && (ret == EINVAL || ret == ENOENT))
+ if (mode != QAM_WRITE &&
+ (ret == DB_PAGE_NOTFOUND || ret == ENOENT))
return (0);
return (ret);
}
@@ -88,7 +87,7 @@ __qam_position(dbc, recnop, mode, exactp)
}
qp = QAM_GET_RECORD(dbp, cp->page, cp->indx);
- *exactp = F_ISSET(qp, QAM_VALID);
+ *exactp = F_ISSET(qp, QAM_VALID) ? 1 : 0;
return (ret);
}
@@ -116,9 +115,9 @@ __qam_pitem(dbc, pagep, indx, recno, data)
DBT olddata, pdata, *datap;
QAMDATA *qp;
QUEUE *t;
- u_int32_t size;
+ u_int32_t alloced;
u_int8_t *dest, *p;
- int alloced, ret;
+ int ret;
alloced = ret = 0;
@@ -131,7 +130,6 @@ __qam_pitem(dbc, pagep, indx, recno, data)
qp = QAM_GET_RECORD(dbp, pagep, indx);
p = qp->data;
- size = data->size;
datap = data;
if (F_ISSET(data, DB_DBT_PARTIAL)) {
if (data->doff + data->dlen > t->re_len) {
@@ -159,12 +157,12 @@ len_err: __db_err(dbp->dbenv,
* to log so that both this and the recovery code is simpler.
*/
- if (DB_LOGGING(dbc) || !F_ISSET(qp, QAM_VALID)) {
+ if (DBC_LOGGING(dbc) || !F_ISSET(qp, QAM_VALID)) {
datap = &pdata;
memset(datap, 0, sizeof(*datap));
if ((ret = __os_malloc(dbp->dbenv,
- t->re_len, NULL, &datap->data)) != 0)
+ t->re_len, &datap->data)) != 0)
return (ret);
alloced = 1;
datap->size = t->re_len;
@@ -188,14 +186,14 @@ len_err: __db_err(dbp->dbenv,
}
no_partial:
- if (DB_LOGGING(dbc)) {
+ if (DBC_LOGGING(dbc)) {
olddata.size = 0;
if (F_ISSET(qp, QAM_SET)) {
olddata.data = qp->data;
olddata.size = t->re_len;
}
- if ((ret = __qam_add_log(dbp->dbenv, dbc->txn, &LSN(pagep),
- 0, dbp->log_fileid, &LSN(pagep), pagep->pgno,
+ if ((ret = __qam_add_log(dbp, dbc->txn, &LSN(pagep),
+ 0, &LSN(pagep), pagep->pgno,
indx, recno, datap, qp->flags,
olddata.size == 0 ? NULL : &olddata)) != 0)
goto err;
@@ -207,7 +205,7 @@ no_partial:
memset(p + datap->size, t->re_pad, t->re_len - datap->size);
err: if (alloced)
- __os_free(datap->data, t->re_len);
+ __os_free(dbp->dbenv, datap->data);
return (ret);
}
@@ -223,23 +221,37 @@ __qam_c_put(dbc, key, data, flags, pgnop)
u_int32_t flags;
db_pgno_t *pgnop;
{
- QUEUE_CURSOR *cp;
DB *dbp;
DB_LOCK lock;
+ DB_MPOOLFILE *mpf;
QMETA *meta;
+ QUEUE_CURSOR *cp;
db_pgno_t pg;
db_recno_t new_cur, new_first;
u_int32_t opcode;
int exact, ret, t_ret;
- COMPQUIET(key, NULL);
-
dbp = dbc->dbp;
+ mpf = dbp->mpf;
if (pgnop != NULL)
*pgnop = PGNO_INVALID;
cp = (QUEUE_CURSOR *)dbc->internal;
+ switch (flags) {
+ case DB_KEYFIRST:
+ case DB_KEYLAST:
+ if ((ret = __qam_getno(dbp, key, &cp->recno)) != 0)
+ return (ret);
+ /* FALLTHROUGH */
+ case DB_CURRENT:
+ break;
+ default:
+ /* The interface shouldn't let anything else through. */
+ DB_ASSERT(0);
+ return (__db_ferr(dbp->dbenv, "__qam_c_put", flags));
+ }
+
/* Write lock the record. */
if ((ret = __db_lget(dbc,
0, cp->recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0)
@@ -252,29 +264,14 @@ __qam_c_put(dbc, key, data, flags, pgnop)
return (ret);
}
- if (exact && flags == DB_NOOVERWRITE) {
- ret = __TLPUT(dbc, lock);
- /* Doing record locking, release the page lock */
- if ((t_ret = __LPUT(dbc, cp->lock)) == 0)
- cp->lock.off = LOCK_INVALID;
- else
- if (ret == 0)
- ret = t_ret;
- if ((t_ret =
- __qam_fput(dbp, cp->pgno, cp->page, 0)) != 0 && ret == 0)
- ret = t_ret;
- cp->page = NULL;
- return (ret == 0 ? DB_KEYEXIST : ret);
- }
-
/* Put the item on the page. */
ret = __qam_pitem(dbc, (QPAGE *)cp->page, cp->indx, cp->recno, data);
/* Doing record locking, release the page lock */
if ((t_ret = __LPUT(dbc, cp->lock)) != 0 && ret == 0)
ret = t_ret;
- if ((t_ret =
- __qam_fput(dbp, cp->pgno, cp->page, DB_MPOOL_DIRTY)) && ret == 0)
+ if ((t_ret = __qam_fput(
+ dbp, cp->pgno, cp->page, DB_MPOOL_DIRTY)) != 0 && ret == 0)
ret = t_ret;
cp->page = NULL;
cp->lock = lock;
@@ -284,11 +281,15 @@ __qam_c_put(dbc, key, data, flags, pgnop)
/* We may need to reset the head or tail of the queue. */
pg = ((QUEUE *)dbp->q_internal)->q_meta;
- if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0)
+
+ /*
+ * Get the meta page first, we don't want to write lock it while
+ * trying to pin it.
+ */
+ if ((ret = mpf->get(mpf, &pg, 0, &meta)) != 0)
return (ret);
- if ((ret = memp_fget(dbp->mpf, &pg, 0, &meta)) != 0) {
- /* We did not fetch it, we can release the lock. */
- (void)__LPUT(dbc, lock);
+ if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0) {
+ (void)mpf->put(mpf, meta, 0);
return (ret);
}
@@ -313,7 +314,8 @@ __qam_c_put(dbc, key, data, flags, pgnop)
} else {
if (QAM_BEFORE_FIRST(meta, cp->recno) &&
(meta->first_recno <= meta->cur_recno ||
- meta->first_recno - cp->recno < cp->recno - meta->cur_recno)) {
+ meta->first_recno - cp->recno <
+ cp->recno - meta->cur_recno)) {
new_first = cp->recno;
opcode |= QAM_SETFIRST;
}
@@ -321,7 +323,8 @@ __qam_c_put(dbc, key, data, flags, pgnop)
if (meta->cur_recno == cp->recno ||
(QAM_AFTER_CURRENT(meta, cp->recno) &&
(meta->first_recno <= meta->cur_recno ||
- cp->recno - meta->cur_recno <= meta->first_recno - cp->recno))) {
+ cp->recno - meta->cur_recno <=
+ meta->first_recno - cp->recno))) {
new_cur = cp->recno + 1;
if (new_cur == RECNO_OOB)
new_cur++;
@@ -329,10 +332,12 @@ __qam_c_put(dbc, key, data, flags, pgnop)
}
}
- if (opcode != 0 && DB_LOGGING(dbc)) {
- ret = __qam_mvptr_log(dbp->dbenv, dbc->txn, &meta->dbmeta.lsn,
- 0, opcode, dbp->log_fileid, meta->first_recno, new_first,
- meta->cur_recno, new_cur, &meta->dbmeta.lsn);
+ if (opcode != 0 && DBC_LOGGING(dbc)) {
+ ret = __qam_mvptr_log(dbp, dbc->txn, &meta->dbmeta.lsn,
+ 0, opcode, meta->first_recno, new_first,
+ meta->cur_recno, new_cur, &meta->dbmeta.lsn, PGNO_BASE_MD);
+ if (ret != 0)
+ opcode = 0;
}
if (opcode & QAM_SETCUR)
@@ -340,9 +345,8 @@ __qam_c_put(dbc, key, data, flags, pgnop)
if (opcode & QAM_SETFIRST)
meta->first_recno = new_first;
- if ((t_ret =
- memp_fput(dbp->mpf, meta, opcode != 0 ? DB_MPOOL_DIRTY : 0)) != 0 &&
- ret == 0)
+ if ((t_ret = mpf->put(
+ mpf, meta, opcode != 0 ? DB_MPOOL_DIRTY : 0)) != 0 && ret == 0)
ret = t_ret;
/* Don't hold the meta page long term. */
@@ -352,70 +356,42 @@ __qam_c_put(dbc, key, data, flags, pgnop)
}
/*
- * __qam_put --
- * Add a record to the queue.
- * If we are doing anything but appending, just call qam_c_put to do the
- * work. Otherwise we fast path things here.
+ * __qam_append --
+ * Perform a put(DB_APPEND) in queue.
*
- * PUBLIC: int __qam_put __P((DB *, DB_TXN *, DBT *, DBT *, u_int32_t));
+ * PUBLIC: int __qam_append __P((DBC *, DBT *, DBT *));
*/
int
-__qam_put(dbp, txn, key, data, flags)
- DB *dbp;
- DB_TXN *txn;
+__qam_append(dbc, key, data)
+ DBC *dbc;
DBT *key, *data;
- u_int32_t flags;
{
- QUEUE_CURSOR *cp;
- DBC *dbc;
+ DB *dbp;
DB_LOCK lock;
+ DB_MPOOLFILE *mpf;
QMETA *meta;
QPAGE *page;
QUEUE *qp;
+ QUEUE_CURSOR *cp;
db_pgno_t pg;
db_recno_t recno;
int ret, t_ret;
- PANIC_CHECK(dbp->dbenv);
- DB_CHECK_TXN(dbp, txn);
-
- /* Allocate a cursor. */
- if ((ret = dbp->cursor(dbp, txn, &dbc, DB_WRITELOCK)) != 0)
- return (ret);
-
- DEBUG_LWRITE(dbc, dbc->txn, "qam_put", key, data, flags);
-
+ dbp = dbc->dbp;
+ mpf = dbp->mpf;
cp = (QUEUE_CURSOR *)dbc->internal;
- /* Check for invalid flags. */
- if ((ret = __db_putchk(dbp,
- key, data, flags, F_ISSET(dbp, DB_AM_RDONLY), 0)) != 0)
- goto done;
-
- /* If not appending, then just call the cursor routine */
- if (flags != DB_APPEND) {
- if ((ret = __qam_getno(dbp, key, &cp->recno)) != 0)
- goto done;
-
- ret = __qam_c_put(dbc, NULL, data, flags, NULL);
- goto done;
- }
-
- /* Write lock the meta page. */
pg = ((QUEUE *)dbp->q_internal)->q_meta;
- if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0)
- goto done;
- if ((ret = memp_fget(dbp->mpf, &pg, 0, &meta)) != 0) {
- /* We did not fetch it, we can release the lock. */
- (void)__LPUT(dbc, lock);
- goto done;
- }
-
- /* Record that we are going to allocate a record. */
- if (DB_LOGGING(dbc)) {
- __qam_inc_log(dbp->dbenv,
- dbc->txn, &meta->dbmeta.lsn,
- 0, dbp->log_fileid, &meta->dbmeta.lsn);
+ /*
+ * Get the meta page first, we don't want to write lock it while
+ * trying to pin it.
+ */
+ if ((ret = mpf->get(mpf, &pg, 0, &meta)) != 0)
+ return (ret);
+ /* Write lock the meta page. */
+ if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0) {
+ (void)mpf->put(mpf, meta, 0);
+ return (ret);
}
/* Get the next record number. */
@@ -436,15 +412,17 @@ __qam_put(dbp, txn, key, data, flags)
meta->first_recno = recno;
/* Lock the record and release meta page lock. */
- if ((ret = __db_lget(dbc,
- 1, recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0)
+ if ((ret = __db_lget(dbc, LCK_COUPLE_ALWAYS,
+ recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0) {
+ (void)__LPUT(dbc, lock);
goto err;
+ }
/*
* The application may modify the data based on the selected record
* number.
*/
- if (flags == DB_APPEND && dbc->dbp->db_append_recno != NULL &&
+ if (dbc->dbp->db_append_recno != NULL &&
(ret = dbc->dbp->db_append_recno(dbc->dbp, data, recno)) != 0) {
(void)__LPUT(dbc, lock);
goto err;
@@ -484,16 +462,20 @@ __qam_put(dbp, txn, key, data, flags)
/* Return the record number to the user. */
if (ret == 0)
- ret = __db_retcopy(dbp, key,
- &recno, sizeof(recno), &dbc->rkey.data, &dbc->rkey.ulen);
+ ret = __db_retcopy(dbp->dbenv, key,
+ &recno, sizeof(recno), &dbc->rkey->data, &dbc->rkey->ulen);
+
+ /* Position the cursor on this record. */
+ cp->recno = recno;
/* See if we are leaving the extent. */
qp = (QUEUE *) dbp->q_internal;
- if (qp->page_ext != 0
- && (recno % (qp->page_ext * qp->rec_page) == 0
- || recno == UINT32_T_MAX)) {
- if ((ret =
- __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0)
+ if (qp->page_ext != 0 &&
+ (recno % (qp->page_ext * qp->rec_page) == 0 ||
+ recno == UINT32_T_MAX)) {
+ if ((ret = __db_lget(dbc,
+ 0, ((QUEUE *)dbp->q_internal)->q_meta,
+ DB_LOCK_WRITE, 0, &lock)) != 0)
goto err;
if (!QAM_AFTER_CURRENT(meta, recno))
ret = __qam_fclose(dbp, pg);
@@ -502,13 +484,7 @@ __qam_put(dbp, txn, key, data, flags)
err:
/* Release the meta page. */
- if ((t_ret
- = memp_fput(dbp->mpf, meta, DB_MPOOL_DIRTY)) != 0 && ret == 0)
- ret = t_ret;
-
-done:
- /* Discard the cursor. */
- if ((t_ret = dbc->c_close(dbc)) != 0 && ret == 0)
+ if ((t_ret = mpf->put(mpf, meta, DB_MPOOL_DIRTY)) != 0 && ret == 0)
ret = t_ret;
return (ret);
@@ -522,50 +498,57 @@ static int
__qam_c_del(dbc)
DBC *dbc;
{
- QUEUE_CURSOR *cp;
DB *dbp;
DBT data;
DB_LOCK lock;
+ DB_MPOOLFILE *mpf;
PAGE *pagep;
QAMDATA *qp;
QMETA *meta;
+ QUEUE_CURSOR *cp;
db_pgno_t pg;
+ db_recno_t first;
int exact, ret, t_ret;
dbp = dbc->dbp;
+ mpf = dbp->mpf;
cp = (QUEUE_CURSOR *)dbc->internal;
pg = ((QUEUE *)dbp->q_internal)->q_meta;
- if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_READ, 0, &lock)) != 0)
+ /*
+ * Get the meta page first, we don't want to write lock it while
+ * trying to pin it.
+ */
+ if ((ret = mpf->get(mpf, &pg, 0, &meta)) != 0)
return (ret);
- if ((ret = memp_fget(dbp->mpf, &pg, 0, &meta)) != 0) {
- /* We did not fetch it, we can release the lock. */
- (void)__LPUT(dbc, lock);
+ /* Write lock the meta page. */
+ if ((ret = __db_lget(dbc, 0, pg, DB_LOCK_READ, 0, &lock)) != 0) {
+ (void)mpf->put(mpf, meta, 0);
return (ret);
}
if (QAM_NOT_VALID(meta, cp->recno))
ret = DB_NOTFOUND;
+ first = meta->first_recno;
+
/* Don't hold the meta page long term. */
if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
ret = t_ret;
- if ((t_ret = memp_fput(dbp->mpf, meta, 0)) != 0 && ret == 0)
- ret = t_ret;
if (ret != 0)
- return (ret);
+ goto err1;
if ((ret = __db_lget(dbc,
0, cp->recno, DB_LOCK_WRITE, DB_LOCK_RECORD, &lock)) != 0)
- return (ret);
+ goto err1;
cp->lock_mode = DB_LOCK_WRITE;
/* Find the record ; delete only deletes exact matches. */
if ((ret = __qam_position(dbc,
&cp->recno, QAM_WRITE, &exact)) != 0) {
cp->lock = lock;
- return (ret);
+ goto err1;
}
if (!exact) {
ret = DB_NOTFOUND;
@@ -575,21 +558,18 @@ __qam_c_del(dbc)
pagep = cp->page;
qp = QAM_GET_RECORD(dbp, pagep, cp->indx);
- if (DB_LOGGING(dbc)) {
- if (((QUEUE *)dbp->q_internal)->page_ext == 0
- || ((QUEUE *)dbp->q_internal)->re_len == 0) {
- if ((ret =
- __qam_del_log(dbp->dbenv,
- dbc->txn, &LSN(pagep), 0,
- dbp->log_fileid, &LSN(pagep),
+ if (DBC_LOGGING(dbc)) {
+ if (((QUEUE *)dbp->q_internal)->page_ext == 0 ||
+ ((QUEUE *)dbp->q_internal)->re_len == 0) {
+ if ((ret = __qam_del_log(dbp,
+ dbc->txn, &LSN(pagep), 0, &LSN(pagep),
pagep->pgno, cp->indx, cp->recno)) != 0)
goto err1;
} else {
data.size = ((QUEUE *)dbp->q_internal)->re_len;
data.data = qp->data;
- if ((ret =
- __qam_delext_log(dbp->dbenv, dbc->txn,
- &LSN(pagep), 0, dbp->log_fileid, &LSN(pagep),
+ if ((ret = __qam_delext_log(dbp,
+ dbc->txn, &LSN(pagep), 0, &LSN(pagep),
pagep->pgno, cp->indx, cp->recno, &data)) != 0)
goto err1;
}
@@ -597,60 +577,28 @@ __qam_c_del(dbc)
F_CLR(qp, QAM_VALID);
-err1:
- if ((t_ret = __qam_fput(
- dbp, cp->pgno, cp->page, ret == 0 ? DB_MPOOL_DIRTY : 0)) != 0)
- return (ret ? ret : t_ret);
- cp->page = NULL;
- /* Doing record locking, release the page lock */
- if ((t_ret = __LPUT(dbc, cp->lock)) != 0) {
- cp->lock = lock;
- return (ret ? ret : t_ret);
+ if (cp->recno == first) {
+ pg = ((QUEUE *)dbp->q_internal)->q_meta;
+ if ((ret =
+ __db_lget(dbc, 0, pg, DB_LOCK_WRITE, 0, &lock)) != 0)
+ goto err1;
+ ret = __qam_consume(dbc, meta, first);
+ if ((t_ret = __LPUT(dbc, lock)) != 0 && ret == 0)
+ ret = t_ret;
}
- cp->lock = lock;
- return (ret);
-}
-/*
- * __qam_delete --
- * Queue db->del function.
- *
- * PUBLIC: int __qam_delete __P((DB *, DB_TXN *, DBT *, u_int32_t));
- */
-int
-__qam_delete(dbp, txn, key, flags)
- DB *dbp;
- DB_TXN *txn;
- DBT *key;
- u_int32_t flags;
-{
- QUEUE_CURSOR *cp;
- DBC *dbc;
- int ret, t_ret;
-
- PANIC_CHECK(dbp->dbenv);
- DB_CHECK_TXN(dbp, txn);
-
- /* Check for invalid flags. */
- if ((ret =
- __db_delchk(dbp, key, flags, F_ISSET(dbp, DB_AM_RDONLY))) != 0)
- return (ret);
-
- /* Acquire a cursor. */
- if ((ret = dbp->cursor(dbp, txn, &dbc, DB_WRITELOCK)) != 0)
- return (ret);
-
- DEBUG_LWRITE(dbc, txn, "qam_delete", key, NULL, flags);
-
- cp = (QUEUE_CURSOR *)dbc->internal;
- if ((ret = __qam_getno(dbp, key, &cp->recno)) != 0)
- goto err;
-
- ret = __qam_c_del(dbc);
+err1:
+ if ((t_ret = mpf->put(mpf, meta, 0)) != 0 && ret == 0)
+ ret = t_ret;
+ if (cp->page != NULL && (t_ret = __qam_fput(dbp, cp->pgno,
+ cp->page, ret == 0 ? DB_MPOOL_DIRTY : 0)) != 0 && ret == 0)
+ ret = t_ret;
+ cp->page = NULL;
- /* Release the cursor. */
-err: if ((t_ret = dbc->c_close(dbc)) != 0 && ret == 0)
+ /* Doing record locking, release the page lock */
+ if ((t_ret = __LPUT(dbc, cp->lock)) != 0 && ret == 0)
ret = t_ret;
+ cp->lock = lock;
return (ret);
}
@@ -671,39 +619,40 @@ __qam_c_get(dbc, key, data, flags, pgnop)
db_pgno_t *pgnop;
{
DB *dbp;
- DB_LOCK lock, pglock, metalock, save_lock;
+ DBC *dbcdup;
DBT tmp;
+ DB_ENV *dbenv;
+ DB_LOCK lock, pglock, metalock;
+ DB_MPOOLFILE *mpf;
PAGE *pg;
QAMDATA *qp;
QMETA *meta;
QUEUE *t;
QUEUE_CURSOR *cp;
- db_indx_t save_indx;
db_lockmode_t lock_mode;
- db_pgno_t metapno, save_page;
- db_recno_t current, first, save_recno;
+ db_pgno_t metapno;
+ db_recno_t first;
qam_position_mode mode;
- u_int32_t rec_extent;
int exact, is_first, locked, ret, t_ret, wait, with_delete;
- int put_mode, meta_dirty, retrying, skip_again, wrapped;
+ int put_mode, meta_dirty, retrying;
- cp = (QUEUE_CURSOR *)dbc->internal;
dbp = dbc->dbp;
+ dbenv = dbp->dbenv;
+ mpf = dbp->mpf;
+ cp = (QUEUE_CURSOR *)dbc->internal;
- PANIC_CHECK(dbp->dbenv);
+ PANIC_CHECK(dbenv);
wait = 0;
with_delete = 0;
retrying = 0;
- rec_extent = 0;
lock_mode = DB_LOCK_READ;
- mode = QAM_READ;
put_mode = 0;
t_ret = 0;
*pgnop = 0;
pg = NULL;
- skip_again = 0;
+ mode = QAM_READ;
if (F_ISSET(dbc, DBC_RMW)) {
lock_mode = DB_LOCK_WRITE;
mode = QAM_WRITE;
@@ -714,7 +663,9 @@ __qam_c_get(dbc, key, data, flags, pgnop)
flags = DB_CONSUME;
}
if (flags == DB_CONSUME) {
- DB_CHECK_TXN(dbp, dbc->txn);
+ if ((ret = __db_check_txn(dbp, dbc->txn, dbc->locker, 0)) != 0)
+ return (ret);
+
with_delete = 1;
flags = DB_FIRST;
lock_mode = DB_LOCK_WRITE;
@@ -724,30 +675,30 @@ __qam_c_get(dbc, key, data, flags, pgnop)
DEBUG_LREAD(dbc, dbc->txn, "qam_c_get",
flags == DB_SET || flags == DB_SET_RANGE ? key : NULL, NULL, flags);
+ /* Make lint and friends happy. */
+ meta_dirty = 0;
+ locked = 0;
+
is_first = 0;
t = (QUEUE *)dbp->q_internal;
- /* get the meta page */
metapno = t->q_meta;
- if ((ret = __db_lget(dbc, 0, metapno, lock_mode, 0, &metalock)) != 0)
+
+ /*
+ * Get the meta page first, we don't want to write lock it while
+ * trying to pin it. This is because someone my have it pinned
+ * but not locked.
+ */
+ if ((ret = mpf->get(mpf, &metapno, 0, &meta)) != 0)
return (ret);
+ if ((ret = __db_lget(dbc, 0, metapno, lock_mode, 0, &metalock)) != 0)
+ goto err;
locked = 1;
- if ((ret = memp_fget(dbp->mpf, &metapno, 0, &meta)) != 0) {
- /* We did not fetch it, we can release the lock. */
- (void)__LPUT(dbc, metalock);
- return (ret);
- }
first = 0;
- /* Make lint and friends happy. */
- meta_dirty = 0;
-
/* Release any previous lock if not in a transaction. */
- if (cp->lock.off != LOCK_INVALID) {
- (void)__TLPUT(dbc, cp->lock);
- cp->lock.off = LOCK_INVALID;
- }
+ (void)__TLPUT(dbc, cp->lock);
retry: /* Update the record number. */
switch (flags) {
@@ -778,8 +729,8 @@ retry: /* Update the record number. */
case DB_PREV:
case DB_PREV_NODUP:
if (cp->recno != RECNO_OOB) {
- if (QAM_BEFORE_FIRST(meta, cp->recno)
- || cp->recno == meta->first_recno) {
+ if (QAM_BEFORE_FIRST(meta, cp->recno) ||
+ cp->recno == meta->first_recno) {
ret = DB_NOTFOUND;
goto err;
}
@@ -799,14 +750,15 @@ retry: /* Update the record number. */
if (cp->recno == RECNO_OOB)
cp->recno--;
break;
- case DB_GET_BOTH:
case DB_SET:
case DB_SET_RANGE:
+ case DB_GET_BOTH:
+ case DB_GET_BOTH_RANGE:
if ((ret = __qam_getno(dbp, key, &cp->recno)) != 0)
goto err;
break;
default:
- ret = __db_unknown_flag(dbp->dbenv, "__qam_c_get", flags);
+ ret = __db_unknown_flag(dbenv, "__qam_c_get", flags);
goto err;
}
@@ -830,14 +782,16 @@ retry: /* Update the record number. */
retrying = 1;
goto retry;
}
- if (CDB_LOCKING(dbp->dbenv)) {
- if ((ret = lock_get(dbp->dbenv, dbc->locker,
+ if (CDB_LOCKING(dbenv)) {
+ if ((ret = dbenv->lock_get(
+ dbenv, dbc->locker,
DB_LOCK_SWITCH, &dbc->lock_dbt,
DB_LOCK_WAIT, &dbc->mylock)) != 0)
goto err;
- if ((ret = lock_get(dbp->dbenv, dbc->locker,
- DB_LOCK_UPGRADE, &dbc->lock_dbt, DB_LOCK_WRITE,
- &dbc->mylock)) != 0)
+ if ((ret = dbenv->lock_get(
+ dbenv, dbc->locker,
+ DB_LOCK_UPGRADE, &dbc->lock_dbt,
+ DB_LOCK_WRITE, &dbc->mylock)) != 0)
goto err;
goto retry;
}
@@ -859,7 +813,7 @@ retry: /* Update the record number. */
if ((ret = __db_lget(dbc, 0, metapno,
DB_LOCK_WAIT, DB_LOCK_SWITCH, &metalock)) != 0)
goto err;
- if ((ret = lock_get(dbp->dbenv, dbc->locker,
+ if ((ret = dbenv->lock_get(dbenv, dbc->locker,
DB_LOCK_UPGRADE, &dbc->lock_dbt, DB_LOCK_WRITE,
&metalock)) != 0)
goto err;
@@ -883,11 +837,15 @@ retry: /* Update the record number. */
DB_LOCK_NOWAIT | DB_LOCK_RECORD : DB_LOCK_RECORD,
&lock)) == DB_LOCK_NOTGRANTED && with_delete) {
#ifdef QDEBUG
- __db_logmsg(dbp->dbenv,
+ __db_logmsg(dbenv,
dbc->txn, "Queue S", 0, "%x %d %d %d",
dbc->locker, cp->recno, first, meta->first_recno);
#endif
first = 0;
+ if ((ret =
+ __db_lget(dbc, 0, metapno, lock_mode, 0, &metalock)) != 0)
+ goto err;
+ locked = 1;
goto retry;
}
@@ -929,9 +887,9 @@ retry: /* Update the record number. */
cp->lock_mode = lock_mode;
if (!exact) {
- if (flags == DB_NEXT || flags == DB_NEXT_NODUP
- || flags == DB_PREV || flags == DB_PREV_NODUP
- || flags == DB_LAST) {
+ if (flags == DB_NEXT || flags == DB_NEXT_NODUP ||
+ flags == DB_PREV || flags == DB_PREV_NODUP ||
+ flags == DB_LAST) {
/* Release locks and try again. */
if (pg != NULL)
(void)__qam_fput(dbp, cp->pgno, pg, 0);
@@ -951,18 +909,20 @@ retry: /* Update the record number. */
}
/* Return the key if the user didn't give us one. */
- if (key != NULL && flags != DB_SET && flags != DB_GET_BOTH &&
- (ret = __db_retcopy(dbp, key, &cp->recno, sizeof(cp->recno),
- &dbc->rkey.data, &dbc->rkey.ulen)) != 0)
- goto err1;
-
- if (key != NULL)
+ if (key != NULL) {
+ if (flags != DB_GET_BOTH && flags != DB_GET_BOTH_RANGE &&
+ flags != DB_SET && flags != DB_SET_RANGE &&
+ (ret = __db_retcopy(dbp->dbenv,
+ key, &cp->recno, sizeof(cp->recno),
+ &dbc->rkey->data, &dbc->rkey->ulen)) != 0)
+ goto err1;
F_SET(key, DB_DBT_ISSET);
+ }
qp = QAM_GET_RECORD(dbp, pg, cp->indx);
/* Return the data item. */
- if (flags == DB_GET_BOTH) {
+ if (flags == DB_GET_BOTH || flags == DB_GET_BOTH_RANGE) {
/*
* Need to compare
*/
@@ -973,8 +933,10 @@ retry: /* Update the record number. */
goto err1;
}
}
- if (data != NULL && (ret = __db_retcopy(dbp, data,
- qp->data, t->re_len, &dbc->rdata.data, &dbc->rdata.ulen)) != 0)
+ if (data != NULL &&
+ !F_ISSET(dbc, DBC_MULTIPLE|DBC_MULTIPLE_KEY) &&
+ (ret = __db_retcopy(dbp->dbenv, data,
+ qp->data, t->re_len, &dbc->rdata->data, &dbc->rdata->ulen)) != 0)
goto err1;
if (data != NULL)
@@ -982,18 +944,53 @@ retry: /* Update the record number. */
/* Finally, if we are doing DB_CONSUME mark the record. */
if (with_delete) {
- if (DB_LOGGING(dbc)) {
+ /*
+ * Assert that we're not a secondary index. Doing a DB_CONSUME
+ * on a secondary makes very little sense, since one can't
+ * DB_APPEND there; attempting one should be forbidden by
+ * the interface.
+ */
+ DB_ASSERT(!F_ISSET(dbp, DB_AM_SECONDARY));
+
+ /*
+ * Check and see if we *have* any secondary indices.
+ * If we do, we're a primary, so call __db_c_del_primary
+ * to delete the references to the item we're about to
+ * delete.
+ *
+ * Note that we work on a duplicated cursor, since the
+ * __db_ret work has already been done, so it's not safe
+ * to perform any additional ops on this cursor.
+ */
+ if (LIST_FIRST(&dbp->s_secondaries) != NULL) {
+ if ((ret = __db_c_idup(dbc,
+ &dbcdup, DB_POSITIONI)) != 0)
+ goto err1;
+
+ if ((ret = __db_c_del_primary(dbcdup)) != 0) {
+ /*
+ * The __db_c_del_primary return is more
+ * interesting.
+ */
+ (void)dbcdup->c_close(dbcdup);
+ goto err1;
+ }
+
+ if ((ret = dbcdup->c_close(dbcdup)) != 0)
+ goto err1;
+ }
+
+ if (DBC_LOGGING(dbc)) {
if (t->page_ext == 0 || t->re_len == 0) {
- if ((ret = __qam_del_log(dbp->dbenv, dbc->txn,
- &LSN(pg), 0, dbp->log_fileid, &LSN(pg),
+ if ((ret = __qam_del_log(dbp, dbc->txn,
+ &LSN(pg), 0, &LSN(pg),
pg->pgno, cp->indx, cp->recno)) != 0)
goto err1;
} else {
tmp.data = qp->data;
tmp.size = t->re_len;
- if ((ret =
- __qam_delext_log(dbp->dbenv, dbc->txn,
- &LSN(pg), 0, dbp->log_fileid, &LSN(pg),
+ if ((ret = __qam_delext_log(dbp,
+ dbc->txn, &LSN(pg), 0, &LSN(pg),
pg->pgno, cp->indx, cp->recno, &tmp)) != 0)
goto err1;
}
@@ -1003,7 +1000,7 @@ retry: /* Update the record number. */
put_mode = DB_MPOOL_DIRTY;
if ((ret = __LPUT(dbc, pglock)) != 0)
- goto err;
+ goto err1;
/*
* Now we need to update the metapage
@@ -1021,8 +1018,9 @@ retry: /* Update the record number. */
dbc, 0, metapno, lock_mode, 0, &metalock)) != 0)
goto err1;
locked = 1;
+
#ifdef QDEBUG
- __db_logmsg(dbp->dbenv,
+ __db_logmsg(dbenv,
dbc->txn, "Queue D", 0, "%x %d %d %d",
dbc->locker, cp->recno, first, meta->first_recno);
#endif
@@ -1037,190 +1035,380 @@ retry: /* Update the record number. */
if (first != meta->first_recno)
goto done;
- save_page = cp->pgno;
- save_indx = cp->indx;
- save_recno = cp->recno;
- save_lock = cp->lock;
+ if ((ret = __qam_consume(dbc, meta, first)) != 0)
+ goto err1;
+ }
- /*
- * If we skipped some deleted records, we need to
- * reposition on the first one. Get a lock
- * in case someone is trying to put it back.
- */
- if (first != cp->recno) {
- ret = __db_lget(dbc, 0, first, DB_LOCK_READ,
- DB_LOCK_NOWAIT | DB_LOCK_RECORD, &lock);
- if (ret == DB_LOCK_NOTGRANTED) {
- ret = 0;
- goto done;
- }
- if (ret != 0)
- goto err1;
- if ((ret =
- __qam_fput(dbp, cp->pgno, cp->page, put_mode)) != 0)
- goto err1;
- cp->page = NULL;
- put_mode = 0;
- if ((ret = __qam_position(dbc,
- &first, QAM_READ, &exact)) != 0 || exact != 0) {
- (void)__LPUT(dbc, lock);
- goto err1;
- }
- if ((ret =__LPUT(dbc, lock)) != 0)
- goto err1;
- if ((ret = __LPUT(dbc, cp->lock)) != 0)
- goto err1;
+done:
+err1: if (cp->page != NULL) {
+ t_ret = __qam_fput(dbp, cp->pgno, cp->page, put_mode);
+
+ if (!ret)
+ ret = t_ret;
+ /* Doing record locking, release the page lock */
+ t_ret = __LPUT(dbc, pglock);
+ cp->page = NULL;
+ }
+
+err: if (!ret)
+ ret = t_ret;
+ if (meta) {
+
+ /* release the meta page */
+ t_ret = mpf->put(mpf, meta, meta_dirty ? DB_MPOOL_DIRTY : 0);
+
+ if (!ret)
+ ret = t_ret;
+
+ /* Don't hold the meta page long term. */
+ if (locked)
+ t_ret = __LPUT(dbc, metalock);
+ }
+ DB_ASSERT(!LOCK_ISSET(metalock));
+
+ /*
+ * There is no need to keep the record locked if we are
+ * not in a transaction.
+ */
+ if (t_ret == 0)
+ t_ret = __TLPUT(dbc, cp->lock);
+
+ return (ret ? ret : t_ret);
+}
+
+/*
+ * __qam_consume -- try to reset the head of the queue.
+ *
+ */
+
+static int
+__qam_consume(dbc, meta, first)
+ DBC *dbc;
+ QMETA *meta;
+ db_recno_t first;
+{
+ DB *dbp;
+ DB_LOCK lock, save_lock;
+ DB_MPOOLFILE *mpf;
+ QUEUE_CURSOR *cp;
+ db_indx_t save_indx;
+ db_pgno_t save_page;
+ db_recno_t current, save_recno;
+ u_int32_t rec_extent;
+ int exact, put_mode, ret, t_ret, wrapped;
+
+ dbp = dbc->dbp;
+ mpf = dbp->mpf;
+ cp = (QUEUE_CURSOR *)dbc->internal;
+ put_mode = DB_MPOOL_DIRTY;
+ ret = t_ret = 0;
+
+ save_page = cp->pgno;
+ save_indx = cp->indx;
+ save_recno = cp->recno;
+ save_lock = cp->lock;
+
+ /*
+ * If we skipped some deleted records, we need to
+ * reposition on the first one. Get a lock
+ * in case someone is trying to put it back.
+ */
+ if (first != cp->recno) {
+ ret = __db_lget(dbc, 0, first, DB_LOCK_READ,
+ DB_LOCK_NOWAIT | DB_LOCK_RECORD, &lock);
+ if (ret == DB_LOCK_NOTGRANTED) {
+ ret = 0;
+ goto done;
}
+ if (ret != 0)
+ goto done;
+ if ((ret =
+ __qam_fput(dbp, cp->pgno, cp->page, put_mode)) != 0)
+ goto done;
+ cp->page = NULL;
+ put_mode = 0;
+ if ((ret = __qam_position(dbc,
+ &first, QAM_READ, &exact)) != 0 || exact != 0) {
+ (void)__LPUT(dbc, lock);
+ goto done;
+ }
+ if ((ret =__LPUT(dbc, lock)) != 0)
+ goto done;
+ if ((ret = __LPUT(dbc, cp->lock)) != 0)
+ goto done;
+ }
- current = meta->cur_recno;
- wrapped = 0;
- if (first > current)
- wrapped = 1;
- rec_extent = meta->page_ext * meta->rec_page;
+ current = meta->cur_recno;
+ wrapped = 0;
+ if (first > current)
+ wrapped = 1;
+ rec_extent = meta->page_ext * meta->rec_page;
- /* Loop until we find a record or hit current */
- for (;;) {
- /*
- * Check to see if we are moving off the extent
- * and remove the extent.
- * If we are moving off a page we need to
- * get rid of the buffer.
- * Wait for the lagging readers to move off the
- * page.
- */
- if (rec_extent != 0
- && ((exact = first % rec_extent == 0)
- || first % meta->rec_page == 0
- || first == UINT32_T_MAX)) {
- if (exact == 1 && (ret = __db_lget(dbc,
- 0, cp->pgno, DB_LOCK_WRITE, 0, &cp->lock)) != 0)
- break;
+ /* Loop until we find a record or hit current */
+ for (;;) {
+ /*
+ * Check to see if we are moving off the extent
+ * and remove the extent.
+ * If we are moving off a page we need to
+ * get rid of the buffer.
+ * Wait for the lagging readers to move off the
+ * page.
+ */
+ if (cp->page != NULL && rec_extent != 0 &&
+ ((exact = (first % rec_extent == 0)) ||
+ first % meta->rec_page == 0 ||
+ first == UINT32_T_MAX)) {
+ if (exact == 1 && (ret = __db_lget(dbc,
+ 0, cp->pgno, DB_LOCK_WRITE, 0, &cp->lock)) != 0)
+ break;
#ifdef QDEBUG
- __db_logmsg(dbp->dbenv,
- dbc->txn, "Queue R", 0, "%x %d %d %d",
- dbc->locker, cp->pgno, first, meta->first_recno);
+ __db_logmsg(dbp->dbenv,
+ dbc->txn, "Queue R", 0, "%x %d %d %d",
+ dbc->locker, cp->pgno, first, meta->first_recno);
#endif
- put_mode |= DB_MPOOL_DISCARD;
- if ((ret = __qam_fput(dbp,
- cp->pgno, cp->page, put_mode)) != 0)
- break;
- cp->page = NULL;
-
- if (exact == 1) {
- ret = __qam_fremove(dbp, cp->pgno);
- t_ret = __LPUT(dbc, cp->lock);
- }
- if (ret != 0)
- break;
- if (t_ret != 0) {
- ret = t_ret;
- break;
- }
- } else if ((ret =
- __qam_fput(dbp, cp->pgno, cp->page, put_mode)) != 0)
+ put_mode |= DB_MPOOL_DISCARD;
+ if ((ret = __qam_fput(dbp,
+ cp->pgno, cp->page, put_mode)) != 0)
break;
cp->page = NULL;
- first++;
- if (first == RECNO_OOB) {
- wrapped = 0;
- first++;
- }
-
- /*
- * LOOP EXIT when we come move to the current
- * pointer.
- */
- if (!wrapped && first >= current)
- break;
- ret = __db_lget(dbc, 0, first, DB_LOCK_READ,
- DB_LOCK_NOWAIT | DB_LOCK_RECORD, &lock);
- if (ret == DB_LOCK_NOTGRANTED) {
- ret = 0;
- break;
+ if (exact == 1) {
+ ret = __qam_fremove(dbp, cp->pgno);
+ t_ret = __LPUT(dbc, cp->lock);
}
if (ret != 0)
break;
-
- if ((ret = __qam_position(dbc,
- &first, QAM_READ, &exact)) != 0) {
- (void)__LPUT(dbc, lock);
- break;
- }
- put_mode = 0;
- if ((ret =__LPUT(dbc, lock)) != 0
- || (ret = __LPUT(dbc, cp->lock)) != 0 ||exact) {
- if ((t_ret = __qam_fput(dbp, cp->pgno,
- cp->page, put_mode)) != 0 && ret == 0)
- ret = t_ret;
- cp->page = NULL;
+ if (t_ret != 0) {
+ ret = t_ret;
break;
}
+ } else if (cp->page != NULL && (ret =
+ __qam_fput(dbp, cp->pgno, cp->page, put_mode)) != 0)
+ break;
+ cp->page = NULL;
+ first++;
+ if (first == RECNO_OOB) {
+ wrapped = 0;
+ first++;
}
- cp->pgno = save_page;
- cp->indx = save_indx;
- cp->recno = save_recno;
- cp->lock = save_lock;
-
/*
- * We have advanced as far as we can.
- * Advance first_recno to this point.
+ * LOOP EXIT when we come move to the current
+ * pointer.
*/
- if (meta->first_recno != first) {
+ if (!wrapped && first >= current)
+ break;
+
+ ret = __db_lget(dbc, 0, first, DB_LOCK_READ,
+ DB_LOCK_NOWAIT | DB_LOCK_RECORD, &lock);
+ if (ret == DB_LOCK_NOTGRANTED) {
+ ret = 0;
+ break;
+ }
+ if (ret != 0)
+ break;
+
+ if ((ret = __qam_position(dbc,
+ &first, QAM_READ, &exact)) != 0) {
+ (void)__LPUT(dbc, lock);
+ break;
+ }
+ put_mode = 0;
+ if ((ret =__LPUT(dbc, lock)) != 0 ||
+ (ret = __LPUT(dbc, cp->lock)) != 0 || exact) {
+ if ((t_ret = __qam_fput(dbp, cp->pgno,
+ cp->page, put_mode)) != 0 && ret == 0)
+ ret = t_ret;
+ cp->page = NULL;
+ break;
+ }
+ }
+
+ cp->pgno = save_page;
+ cp->indx = save_indx;
+ cp->recno = save_recno;
+ cp->lock = save_lock;
+
+ /*
+ * We have advanced as far as we can.
+ * Advance first_recno to this point.
+ */
+ if (ret == 0 && meta->first_recno != first) {
#ifdef QDEBUG
__db_logmsg(dbp->dbenv, dbc->txn, "Queue M",
0, "%x %d %d %d", dbc->locker, cp->recno,
first, meta->first_recno);
#endif
- if (DB_LOGGING(dbc))
- if ((ret =
- __qam_incfirst_log(dbp->dbenv,
- dbc->txn, &meta->dbmeta.lsn, 0,
- dbp->log_fileid, cp->recno)) != 0)
- goto err;
- meta->first_recno = first;
- meta_dirty = 1;
- }
+ if (DBC_LOGGING(dbc))
+ if ((ret = __qam_incfirst_log(dbp,
+ dbc->txn, &meta->dbmeta.lsn, 0,
+ cp->recno, PGNO_BASE_MD)) != 0)
+ goto done;
+ meta->first_recno = first;
+ (void)mpf->set(mpf, meta, DB_MPOOL_DIRTY);
}
done:
-err1: if (cp->page != NULL) {
- t_ret = __qam_fput(dbp, cp->pgno, cp->page, put_mode);
+ return (ret);
+}
- if (!ret)
+static int
+__qam_bulk(dbc, data, flags)
+ DBC *dbc;
+ DBT *data;
+ u_int32_t flags;
+{
+ DB *dbp;
+ DB_LOCK metalock;
+ DB_MPOOLFILE *mpf;
+ PAGE *pg;
+ QMETA *meta;
+ QAMDATA *qp;
+ QUEUE_CURSOR *cp;
+ db_indx_t indx;
+ db_pgno_t metapno;
+ qam_position_mode mode;
+ int32_t *endp, *offp;
+ u_int8_t *dbuf, *dp, *np;
+ int exact, recs, re_len, ret, t_ret, valid;
+ int is_key, need_pg, pagesize, size, space;
+
+ dbp = dbc->dbp;
+ mpf = dbp->mpf;
+ cp = (QUEUE_CURSOR *)dbc->internal;
+
+ mode = QAM_READ;
+ if (F_ISSET(dbc, DBC_RMW))
+ mode = QAM_WRITE;
+
+ pagesize = dbp->pgsize;
+ re_len = ((QUEUE *)dbp->q_internal)->re_len;
+ recs = ((QUEUE *)dbp->q_internal)->rec_page;
+ metapno = ((QUEUE *)dbp->q_internal)->q_meta;
+
+ is_key = LF_ISSET(DB_MULTIPLE_KEY) ? 1 : 0;
+ size = 0;
+
+ if ((ret = __db_lget(dbc, 0, metapno, DB_LOCK_READ, 0, &metalock)) != 0)
+ return (ret);
+ if ((ret = mpf->get(mpf, &metapno, 0, &meta)) != 0) {
+ /* We did not fetch it, we can release the lock. */
+ (void)__LPUT(dbc, metalock);
+ return (ret);
+ }
+
+ dbuf = data->data;
+ np = dp = dbuf;
+
+ /* Keep track of space that is left. There is an termination entry */
+ space = data->ulen;
+ space -= sizeof(*offp);
+
+ /* Build the offset/size table form the end up. */
+ endp = (int32_t *) ((u_int8_t *)dbuf + data->ulen);
+ endp--;
+ offp = endp;
+
+next_pg:
+ if ((ret = __qam_position(dbc, &cp->recno, mode, &exact)) != 0)
+ goto done;
+
+ pg = cp->page;
+ indx = cp->indx;
+ need_pg = 1;
+
+ do {
+ /*
+ * If this page is a nonexistent page at the end of an
+ * extent, pg may be NULL. A NULL page has no valid records,
+ * so just keep looping as though qp exists and isn't QAM_VALID;
+ * calling QAM_GET_RECORD is unsafe.
+ */
+ valid = 0;
+
+ /* Wrap around, skipping zero. */
+ if (cp->recno == RECNO_OOB)
+ cp->recno++;
+ if (pg != NULL) {
+ qp = QAM_GET_RECORD(dbp, pg, indx);
+ if (F_ISSET(qp, QAM_VALID)) {
+ valid = 1;
+ space -= (is_key ? 3 : 2) * sizeof(*offp);
+ if (space < 0)
+ goto get_space;
+ if (need_pg) {
+ dp = np;
+ size = pagesize - QPAGE_SZ(dbp);
+ if (space < size) {
+get_space:
+ if (offp == endp) {
+ data->size =
+ ALIGN(size +
+ pagesize,
+ sizeof(u_int32_t));
+ ret = ENOMEM;
+ break;
+ }
+ if (indx != 0)
+ indx--;
+ cp->recno--;
+ break;
+ }
+ memcpy(dp,
+ (char *)pg + QPAGE_SZ(dbp), size);
+ need_pg = 0;
+ space -= size;
+ np += size;
+ }
+ if (is_key)
+ *offp-- = cp->recno;
+ *offp-- = (int32_t)((u_int8_t*)qp -
+ (u_int8_t*)pg - QPAGE_SZ(dbp) +
+ dp - dbuf + SSZA(QAMDATA, data));
+ *offp-- = re_len;
+ }
+ }
+ if (!valid && is_key == 0) {
+ *offp-- = 0;
+ *offp-- = 0;
+ }
+ cp->recno++;
+ } while (++indx < recs && indx != RECNO_OOB
+ && cp->recno != meta->cur_recno
+ && !QAM_AFTER_CURRENT(meta, cp->recno));
+
+ if ((t_ret = __TLPUT(dbc, cp->lock)) != 0 && ret == 0)
+ ret = t_ret;
+
+ if (cp->page != NULL) {
+ if ((t_ret =
+ __qam_fput(dbp, cp->pgno, cp->page, 0)) != 0 && ret == 0)
ret = t_ret;
- /* Doing record locking, release the page lock */
- t_ret = __LPUT(dbc, pglock);
cp->page = NULL;
}
-err: if (!ret)
- ret = t_ret;
- if (meta) {
+ if (ret == 0
+ && (indx >= recs || indx == RECNO_OOB)
+ && cp->recno != meta->cur_recno
+ && !QAM_AFTER_CURRENT(meta, cp->recno))
+ goto next_pg;
- /* release the meta page */
- t_ret = memp_fput(
- dbp->mpf, meta, meta_dirty ? DB_MPOOL_DIRTY : 0);
+ if (is_key == 1)
+ *offp = RECNO_OOB;
+ else
+ *offp = -1;
- if (!ret)
- ret = t_ret;
+done:
+ /* release the meta page */
+ t_ret = mpf->put(mpf, meta, 0);
- /* Don't hold the meta page long term. */
- if (locked)
- t_ret = __LPUT(dbc, metalock);
- }
- DB_ASSERT(metalock.off == LOCK_INVALID);
+ if (!ret)
+ ret = t_ret;
- /*
- * There is no need to keep the record locked if we are
- * not in a transaction.
- */
- if (t_ret == 0)
- t_ret = __TLPUT(dbc, cp->lock);
+ t_ret = __LPUT(dbc, metalock);
- return (ret ? ret : t_ret);
+ return (ret);
}
/*
@@ -1241,15 +1429,12 @@ __qam_c_close(dbc, root_pgno, rmroot)
cp = (QUEUE_CURSOR *)dbc->internal;
/* Discard any locks not acquired inside of a transaction. */
- if (cp->lock.off != LOCK_INVALID) {
- (void)__TLPUT(dbc, cp->lock);
- cp->lock.off = LOCK_INVALID;
- }
+ (void)__TLPUT(dbc, cp->lock);
+ LOCK_INIT(cp->lock);
cp->page = NULL;
cp->pgno = PGNO_INVALID;
cp->indx = 0;
- cp->lock.off = LOCK_INVALID;
cp->lock_mode = DB_LOCK_NG;
cp->recno = RECNO_OOB;
cp->flags = 0;
@@ -1277,7 +1462,7 @@ __qam_c_dup(orig_dbc, new_dbc)
/* reget the long term lock if we are not in a xact */
if (orig_dbc->txn != NULL ||
- !STD_LOCKING(orig_dbc) || orig->lock.off == LOCK_INVALID)
+ !STD_LOCKING(orig_dbc) || !LOCK_ISSET(orig->lock))
return (0);
return (__db_lget(new_dbc,
@@ -1313,8 +1498,10 @@ __qam_c_init(dbc)
dbc->c_count = __db_c_count;
dbc->c_del = __db_c_del;
dbc->c_dup = __db_c_dup;
- dbc->c_get = __db_c_get;
+ dbc->c_get = dbc->c_real_get = __db_c_get;
+ dbc->c_pget = __db_c_pget;
dbc->c_put = __db_c_put;
+ dbc->c_am_bulk = __qam_bulk;
dbc->c_am_close = __qam_c_close;
dbc->c_am_del = __qam_c_del;
dbc->c_am_destroy = __qam_c_destroy;
@@ -1334,7 +1521,7 @@ __qam_c_destroy(dbc)
DBC *dbc;
{
/* Discard the structures. */
- __os_free(dbc->internal, sizeof(QUEUE_CURSOR));
+ __os_free(dbc->dbp->dbenv, dbc->internal);
return (0);
}
@@ -1355,3 +1542,74 @@ __qam_getno(dbp, key, rep)
}
return (0);
}
+
+/*
+ * __qam_truncate --
+ * Truncate a queue database
+ *
+ * PUBLIC: int __qam_truncate __P((DB *, DB_TXN *, u_int32_t *));
+ */
+int
+__qam_truncate(dbp, txn, countp)
+ DB *dbp;
+ DB_TXN *txn;
+ u_int32_t *countp;
+{
+ DBC *dbc;
+ DB_LOCK metalock;
+ DB_MPOOLFILE *mpf;
+ QMETA *meta;
+ db_pgno_t metapno;
+ int count, ret, t_ret;
+
+ mpf = dbp->mpf;
+
+ /* Acquire a cursor. */
+ if ((ret = dbp->cursor(dbp, txn, &dbc, 0)) != 0)
+ return (ret);
+
+ /* Walk the queue, counting rows. */
+ count = 0;
+ while ((ret = __qam_c_get(dbc, NULL, NULL, DB_CONSUME, &metapno)) == 0)
+ count++;
+
+ if (ret == DB_NOTFOUND)
+ ret = 0;
+
+ /* Discard the cursor. */
+ if ((t_ret = dbc->c_close(dbc)) != 0 && ret == 0)
+ ret = t_ret;
+
+ if (ret != 0)
+ return (ret);
+
+ /* update the meta page */
+ /* get the meta page */
+ metapno = ((QUEUE *)dbp->q_internal)->q_meta;
+ if ((ret =
+ __db_lget(dbc, 0, metapno, DB_LOCK_WRITE, 0, &metalock)) != 0)
+ return (ret);
+
+ if ((ret = mpf->get(mpf, &metapno, 0, &meta)) != 0) {
+ /* We did not fetch it, we can release the lock. */
+ (void)__LPUT(dbc, metalock);
+ return (ret);
+ }
+ if (DBC_LOGGING(dbc)) {
+ ret = __qam_mvptr_log(dbp, dbc->txn, &meta->dbmeta.lsn, 0,
+ QAM_SETCUR | QAM_SETFIRST | QAM_TRUNCATE, meta->first_recno,
+ 1, meta->cur_recno, 1, &meta->dbmeta.lsn, PGNO_BASE_MD);
+ }
+ if (ret == 0)
+ meta->first_recno = meta->cur_recno = 1;
+
+ if ((t_ret =
+ mpf->put(mpf, meta, ret == 0 ? DB_MPOOL_DIRTY: 0)) != 0 && ret == 0)
+ ret = t_ret;
+ if ((t_ret = __LPUT(dbc, metalock)) != 0 && ret == 0)
+ ret = t_ret;
+
+ *countp = count;
+
+ return (ret);
+}
diff --git a/bdb/qam/qam.src b/bdb/qam/qam.src
index 507d7a65229..f8bf4da4dd0 100644
--- a/bdb/qam/qam.src
+++ b/bdb/qam/qam.src
@@ -1,13 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*
- * $Id: qam.src,v 11.15 2001/01/16 20:10:55 ubell Exp $
+ * $Id: qam.src,v 11.28 2002/04/17 19:03:13 krinsky Exp $
*/
-PREFIX qam
+PREFIX __qam
+DBPRIVATE
INCLUDE #include "db_config.h"
INCLUDE
@@ -15,61 +16,55 @@ INCLUDE #ifndef NO_SYSTEM_INCLUDES
INCLUDE #include <sys/types.h>
INCLUDE
INCLUDE #include <ctype.h>
-INCLUDE #include <errno.h>
INCLUDE #include <string.h>
INCLUDE #endif
INCLUDE
INCLUDE #include "db_int.h"
-INCLUDE #include "db_page.h"
-INCLUDE #include "db_dispatch.h"
-INCLUDE #include "db_am.h"
-INCLUDE #include "qam.h"
-INCLUDE #include "txn.h"
+INCLUDE #include "dbinc/crypto.h"
+INCLUDE #include "dbinc/db_page.h"
+INCLUDE #include "dbinc/db_dispatch.h"
+INCLUDE #include "dbinc/db_am.h"
+INCLUDE #include "dbinc/log.h"
+INCLUDE #include "dbinc/qam.h"
+INCLUDE #include "dbinc/rep.h"
+INCLUDE #include "dbinc/txn.h"
INCLUDE
/*
- * inc
- * Used when we increment a record number. These do not actually
- * tell you what record number you got, just that you incremented
- * the record number. These operations are never undone.
- */
-BEGIN inc 76
-ARG fileid int32_t ld
-POINTER lsn DB_LSN * lu
-END
-
-/*
* incfirst
* Used when we increment first_recno.
*/
-BEGIN incfirst 77
-ARG fileid int32_t ld
+BEGIN incfirst 84
+DB fileid int32_t ld
ARG recno db_recno_t lu
+WRLOCK meta_pgno db_pgno_t lu
END
/*
* mvptr
* Used when we change one or both of cur_recno and first_recno.
*/
-BEGIN mvptr 78
+BEGIN mvptr 85
ARG opcode u_int32_t lu
-ARG fileid int32_t ld
+DB fileid int32_t ld
ARG old_first db_recno_t lu
ARG new_first db_recno_t lu
ARG old_cur db_recno_t lu
ARG new_cur db_recno_t lu
POINTER metalsn DB_LSN * lu
+WRLOCK meta_pgno db_pgno_t lu
END
+
/*
* del
* Used when we delete a record.
* recno is the record that is being deleted.
*/
BEGIN del 79
-ARG fileid int32_t ld
+DB fileid int32_t ld
POINTER lsn DB_LSN * lu
-ARG pgno db_pgno_t lu
+WRLOCK pgno db_pgno_t lu
ARG indx u_int32_t lu
ARG recno db_recno_t lu
END
@@ -81,9 +76,9 @@ END
* data is the record itself.
*/
BEGIN add 80
-ARG fileid int32_t ld
+DB fileid int32_t ld
POINTER lsn DB_LSN * lu
-ARG pgno db_pgno_t lu
+WRLOCK pgno db_pgno_t lu
ARG indx u_int32_t lu
ARG recno db_recno_t lu
DBT data DBT s
@@ -92,30 +87,12 @@ DBT olddata DBT s
END
/*
- * delete
- * Used when we remove a Queue extent file.
- */
-BEGIN delete 81
-DBT name DBT s
-POINTER lsn DB_LSN * lu
-END
-
-/*
- * rename
- * Used when we rename a Queue extent file.
- */
-BEGIN rename 82
-DBT name DBT s
-DBT newname DBT s
-END
-
-/*
* delext
* Used when we delete a record in extent based queue.
* recno is the record that is being deleted.
*/
BEGIN delext 83
-ARG fileid int32_t ld
+DB fileid int32_t ld
POINTER lsn DB_LSN * lu
ARG pgno db_pgno_t lu
ARG indx u_int32_t lu
diff --git a/bdb/qam/qam_conv.c b/bdb/qam/qam_conv.c
index 2eb1c7227e6..d89fe06b0cf 100644
--- a/bdb/qam/qam_conv.c
+++ b/bdb/qam/qam_conv.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_conv.c,v 11.6 2000/11/16 23:40:57 ubell Exp $";
+static const char revid[] = "$Id: qam_conv.c,v 11.14 2002/08/06 06:17:02 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -16,10 +16,9 @@ static const char revid[] = "$Id: qam_conv.c,v 11.6 2000/11/16 23:40:57 ubell Ex
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "qam.h"
-#include "db_swap.h"
-#include "db_am.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_swap.h"
+#include "dbinc/db_am.h"
/*
* __qam_mswap --
@@ -43,6 +42,8 @@ __qam_mswap(pg)
SWAP32(p); /* re_pad */
SWAP32(p); /* rec_page */
SWAP32(p); /* page_ext */
+ p += 91 * sizeof(u_int32_t); /* unused */
+ SWAP32(p); /* crypto_magic */
return (0);
}
@@ -68,7 +69,7 @@ __qam_pgin_out(dbenv, pg, pp, cookie)
COMPQUIET(pg, 0);
COMPQUIET(dbenv, NULL);
pginfo = (DB_PGINFO *)cookie->data;
- if (!pginfo->needswap)
+ if (!F_ISSET(pginfo, DB_AM_SWAP))
return (0);
h = pp;
diff --git a/bdb/qam/qam_files.c b/bdb/qam/qam_files.c
index e53a3bf24c0..f15a88d546d 100644
--- a/bdb/qam/qam_files.c
+++ b/bdb/qam/qam_files.c
@@ -1,67 +1,65 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_files.c,v 1.16 2001/01/19 18:01:59 bostic Exp $";
+static const char revid[] = "$Id: qam_files.c,v 1.52 2002/08/26 17:52:18 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
+#include <stdlib.h>
#include <string.h>
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_shash.h"
-#include "db_am.h"
-#include "lock.h"
-#include "btree.h"
-#include "qam.h"
-#include "mp.h"
+#include "dbinc/db_page.h"
+#include "dbinc/qam.h"
+#include "dbinc/db_am.h"
/*
- * __qam_fprobe -- calcluate and open extent
+ * __qam_fprobe -- calculate and open extent
*
- * Calculate which extent the page is in, open and create
- * if necessary.
+ * Calculate which extent the page is in, open and create if necessary.
*
- * PUBLIC: int __qam_fprobe __P((DB *, db_pgno_t, void *, qam_probe_mode, int));
+ * PUBLIC: int __qam_fprobe
+ * PUBLIC: __P((DB *, db_pgno_t, void *, qam_probe_mode, u_int32_t));
*/
-
int
__qam_fprobe(dbp, pgno, addrp, mode, flags)
DB *dbp;
db_pgno_t pgno;
void *addrp;
qam_probe_mode mode;
- int flags;
+ u_int32_t flags;
{
DB_ENV *dbenv;
DB_MPOOLFILE *mpf;
MPFARRAY *array;
QUEUE *qp;
- u_int32_t extid, maxext;
- char buf[256];
- int numext, offset, oldext, openflags, ret;
+ u_int8_t fid[DB_FILE_ID_LEN];
+ u_int32_t extid, maxext, openflags;
+ char buf[MAXPATHLEN];
+ int numext, offset, oldext, ret;
+ dbenv = dbp->dbenv;
qp = (QUEUE *)dbp->q_internal;
+ ret = 0;
+
if (qp->page_ext == 0) {
mpf = dbp->mpf;
- if (mode == QAM_PROBE_GET)
- return (memp_fget(mpf, &pgno, flags, addrp));
- return (memp_fput(mpf, addrp, flags));
+ return (mode == QAM_PROBE_GET ?
+ mpf->get(mpf, &pgno, flags, addrp) :
+ mpf->put(mpf, addrp, flags));
}
- dbenv = dbp->dbenv;
mpf = NULL;
- ret = 0;
/*
* Need to lock long enough to find the mpf or create the file.
@@ -92,36 +90,48 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
/*
* Check to see if the requested extent is outside the range of
- * extents in the array. This is true by defualt if there are
+ * extents in the array. This is true by default if there are
* no extents here yet.
*/
if (offset < 0 || (unsigned) offset >= array->n_extent) {
oldext = array->n_extent;
- numext = array->hi_extent - array->low_extent + 1;
- if (offset < 0
- && (unsigned) -offset + numext <= array->n_extent) {
- /* If we can fit this one in, move the array up */
+ numext = array->hi_extent - array->low_extent + 1;
+ if (offset < 0 &&
+ (unsigned) -offset + numext <= array->n_extent) {
+ /*
+ * If we can fit this one into the existing array by
+ * shifting the existing entries then we do not have
+ * to allocate.
+ */
memmove(&array->mpfarray[-offset],
array->mpfarray, numext
* sizeof(array->mpfarray[0]));
memset(array->mpfarray, 0, -offset
- * sizeof(array->mpfarray[0]));
+ * sizeof(array->mpfarray[0]));
offset = 0;
} else if ((u_int32_t)offset == array->n_extent &&
mode != QAM_PROBE_MPF && array->mpfarray[0].pinref == 0) {
- /* We can close the bottom extent. */
+ /*
+ * If this is at the end of the array and the file at
+ * the begining has a zero pin count we can close
+ * the bottom extent and put this one at the end.
+ */
mpf = array->mpfarray[0].mpf;
- if (mpf != NULL && (ret = memp_fclose(mpf)) != 0)
+ if (mpf != NULL && (ret = mpf->close(mpf, 0)) != 0)
goto err;
memmove(&array->mpfarray[0], &array->mpfarray[1],
- (array->n_extent - 1) * sizeof (array->mpfarray[0]));
+ (array->n_extent - 1) * sizeof(array->mpfarray[0]));
array->low_extent++;
array->hi_extent++;
offset--;
array->mpfarray[offset].mpf = NULL;
array->mpfarray[offset].pinref = 0;
} else {
- /* See if we have wrapped around the queue. */
+ /*
+ * See if we have wrapped around the queue.
+ * If it has then allocate the second array.
+ * Otherwise just expand the one we are using.
+ */
maxext = (u_int32_t) UINT32_T_MAX
/ (qp->page_ext * qp->rec_page);
if ((u_int32_t) abs(offset) >= maxext/2) {
@@ -143,51 +153,73 @@ __qam_fprobe(dbp, pgno, addrp, mode, flags)
alloc:
if ((ret = __os_realloc(dbenv,
array->n_extent * sizeof(struct __qmpf),
- NULL, &array->mpfarray)) != 0)
+ &array->mpfarray)) != 0)
goto err;
if (offset < 0) {
+ /*
+ * Move the array up and put the new one
+ * in the first slot.
+ */
offset = -offset;
- memmove(&array->mpfarray[offset], array->mpfarray,
+ memmove(&array->mpfarray[offset],
+ array->mpfarray,
numext * sizeof(array->mpfarray[0]));
memset(array->mpfarray, 0,
offset * sizeof(array->mpfarray[0]));
memset(&array->mpfarray[numext + offset], 0,
- (array->n_extent - (numext + offset))
- * sizeof(array->mpfarray[0]));
+ (array->n_extent - (numext + offset))
+ * sizeof(array->mpfarray[0]));
offset = 0;
}
else
+ /* Clear the new part of the array. */
memset(&array->mpfarray[oldext], 0,
(array->n_extent - oldext) *
sizeof(array->mpfarray[0]));
}
}
+ /* Update the low and hi range of saved extents. */
if (extid < array->low_extent)
array->low_extent = extid;
if (extid > array->hi_extent)
array->hi_extent = extid;
+
+ /* If the extent file is not yet open, open it. */
if (array->mpfarray[offset].mpf == NULL) {
- snprintf(buf,
- sizeof(buf), QUEUE_EXTENT, qp->dir, qp->name, extid);
+ snprintf(buf, sizeof(buf),
+ QUEUE_EXTENT, qp->dir, PATH_SEPARATOR[0], qp->name, extid);
+ if ((ret = dbenv->memp_fcreate(
+ dbenv, &array->mpfarray[offset].mpf, 0)) != 0)
+ goto err;
+ mpf = array->mpfarray[offset].mpf;
+ (void)mpf->set_lsn_offset(mpf, 0);
+ (void)mpf->set_pgcookie(mpf, &qp->pgcookie);
+
+ /* Set up the fileid for this extent. */
+ __qam_exid(dbp, fid, extid);
+ (void)mpf->set_fileid(mpf, fid);
openflags = DB_EXTENT;
if (LF_ISSET(DB_MPOOL_CREATE))
openflags |= DB_CREATE;
if (F_ISSET(dbp, DB_AM_RDONLY))
openflags |= DB_RDONLY;
- qp->finfo.fileid = NULL;
- if ((ret = __memp_fopen(dbenv->mp_handle,
- NULL, buf, openflags, qp->mode, dbp->pgsize,
- 1, &qp->finfo, &array->mpfarray[offset].mpf)) != 0)
+ if (F_ISSET(dbenv, DB_ENV_DIRECT_DB))
+ openflags |= DB_DIRECT;
+ if ((ret = mpf->open(
+ mpf, buf, openflags, qp->mode, dbp->pgsize)) != 0) {
+ array->mpfarray[offset].mpf = NULL;
+ (void)mpf->close(mpf, 0);
goto err;
+ }
}
mpf = array->mpfarray[offset].mpf;
if (mode == QAM_PROBE_GET)
array->mpfarray[offset].pinref++;
if (LF_ISSET(DB_MPOOL_CREATE))
- __memp_clear_unlink(mpf);
+ mpf->set_unlink(mpf, 0);
err:
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
@@ -200,9 +232,8 @@ err:
pgno--;
pgno %= qp->page_ext;
if (mode == QAM_PROBE_GET)
- return (memp_fget(mpf,
- &pgno, flags | DB_MPOOL_EXTENT, addrp));
- ret = memp_fput(mpf, addrp, flags);
+ return (mpf->get(mpf, &pgno, flags, addrp));
+ ret = mpf->put(mpf, addrp, flags);
MUTEX_THREAD_LOCK(dbenv, dbp->mutexp);
array->mpfarray[offset].pinref--;
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
@@ -218,7 +249,6 @@ err:
*
* PUBLIC: int __qam_fclose __P((DB *, db_pgno_t));
*/
-
int
__qam_fclose(dbp, pgnoaddr)
DB *dbp;
@@ -251,12 +281,13 @@ __qam_fclose(dbp, pgnoaddr)
mpf = array->mpfarray[offset].mpf;
array->mpfarray[offset].mpf = NULL;
- ret = memp_fclose(mpf);
+ ret = mpf->close(mpf, 0);
done:
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
return (ret);
}
+
/*
* __qam_fremove -- remove an extent.
*
@@ -266,7 +297,6 @@ done:
*
* PUBLIC: int __qam_fremove __P((DB *, db_pgno_t));
*/
-
int
__qam_fremove(dbp, pgnoaddr)
DB *dbp;
@@ -278,7 +308,7 @@ __qam_fremove(dbp, pgnoaddr)
QUEUE *qp;
u_int32_t extid;
#if CONFIG_TEST
- char buf[256], *real_name;
+ char buf[MAXPATHLEN], *real_name;
#endif
int offset, ret;
@@ -300,22 +330,34 @@ __qam_fremove(dbp, pgnoaddr)
real_name = NULL;
/* Find the real name of the file. */
snprintf(buf, sizeof(buf),
- QUEUE_EXTENT, qp->dir, qp->name, extid);
+ QUEUE_EXTENT, qp->dir, PATH_SEPARATOR[0], qp->name, extid);
if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, buf, 0, NULL, &real_name)) != 0)
+ DB_APP_DATA, buf, 0, NULL, &real_name)) != 0)
goto err;
#endif
+ /*
+ * The log must be flushed before the file is deleted. We depend on
+ * the log record of the last delete to recreate the file if we crash.
+ */
+ if (LOGGING_ON(dbenv) && (ret = dbenv->log_flush(dbenv, NULL)) != 0)
+ goto err;
+
mpf = array->mpfarray[offset].mpf;
array->mpfarray[offset].mpf = NULL;
- __memp_set_unlink(mpf);
- if ((ret = memp_fclose(mpf)) != 0)
+ mpf->set_unlink(mpf, 1);
+ if ((ret = mpf->close(mpf, 0)) != 0)
goto err;
+ /*
+ * If the file is at the bottom of the array
+ * shift things down and adjust the end points.
+ */
if (offset == 0) {
memmove(array->mpfarray, &array->mpfarray[1],
(array->hi_extent - array->low_extent)
* sizeof(array->mpfarray[0]));
- array->mpfarray[array->hi_extent - array->low_extent].mpf = NULL;
+ array->mpfarray[
+ array->hi_extent - array->low_extent].mpf = NULL;
if (array->low_extent != array->hi_extent)
array->low_extent++;
} else {
@@ -327,7 +369,7 @@ err:
MUTEX_THREAD_UNLOCK(dbenv, dbp->mutexp);
#if CONFIG_TEST
if (real_name != NULL)
- __os_freestr(real_name);
+ __os_free(dbenv, real_name);
#endif
return (ret);
}
@@ -353,6 +395,7 @@ __qam_sync(dbp, flags)
int done, ret;
dbenv = dbp->dbenv;
+ mpf = dbp->mpf;
PANIC_CHECK(dbenv);
DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->sync");
@@ -369,7 +412,7 @@ __qam_sync(dbp, flags)
return (0);
/* Flush any dirty pages from the cache to the backing file. */
- if ((ret = memp_fsync(dbp->mpf)) != 0)
+ if ((ret = mpf->sync(dbp->mpf)) != 0)
return (ret);
qp = (QUEUE *)dbp->q_internal;
@@ -383,7 +426,7 @@ __qam_sync(dbp, flags)
if (filelist == NULL)
return (0);
- __os_free(filelist, 0);
+ __os_free(dbp->dbenv, filelist);
done = 0;
qp = (QUEUE *)dbp->q_internal;
@@ -394,7 +437,7 @@ again:
mpfp = array->mpfarray;
for (i = array->low_extent; i <= array->hi_extent; i++, mpfp++)
if ((mpf = mpfp->mpf) != NULL) {
- if ((ret = memp_fsync(mpf)) != 0)
+ if ((ret = mpf->sync(mpf)) != 0)
goto err;
/*
* If we are the only ones with this file open
@@ -402,7 +445,7 @@ again:
*/
if (mpfp->pinref == 0) {
mpfp->mpf = NULL;
- if ((ret = memp_fclose(mpf)) != 0)
+ if ((ret = mpf->close(mpf, 0)) != 0)
goto err;
}
}
@@ -431,16 +474,19 @@ __qam_gen_filelist(dbp, filelistp)
QUEUE_FILELIST **filelistp;
{
DB_ENV *dbenv;
+ DB_MPOOLFILE *mpf;
QUEUE *qp;
QMETA *meta;
- db_pgno_t i, last, start, stop;
+ db_pgno_t i, last, start;
db_recno_t current, first;
QUEUE_FILELIST *fp;
int ret;
dbenv = dbp->dbenv;
+ mpf = dbp->mpf;
qp = (QUEUE *)dbp->q_internal;
*filelistp = NULL;
+
if (qp->page_ext == 0)
return (0);
@@ -450,18 +496,14 @@ __qam_gen_filelist(dbp, filelistp)
/* Find out the page number of the last page in the database. */
i = PGNO_BASE_MD;
- if ((ret = memp_fget(dbp->mpf, &i, 0, &meta)) != 0) {
- (void)dbp->close(dbp, 0);
+ if ((ret = mpf->get(mpf, &i, 0, &meta)) != 0)
return (ret);
- }
current = meta->cur_recno;
first = meta->first_recno;
- if ((ret = memp_fput(dbp->mpf, meta, 0)) != 0) {
- (void)dbp->close(dbp, 0);
+ if ((ret = mpf->put(mpf, meta, 0)) != 0)
return (ret);
- }
last = QAM_RECNO_PAGE(dbp, current);
start = QAM_RECNO_PAGE(dbp, first);
@@ -476,14 +518,10 @@ __qam_gen_filelist(dbp, filelistp)
return (ret);
fp = *filelistp;
i = start;
- if (last >= start)
- stop = last;
- else
- stop = QAM_RECNO_PAGE(dbp, UINT32_T_MAX);
-again:
- for (; i <= last; i += qp->page_ext) {
- if ((ret = __qam_fprobe(dbp,
- i, &fp->mpf, QAM_PROBE_MPF, 0)) != 0) {
+
+again: for (; i <= last; i += qp->page_ext) {
+ if ((ret =
+ __qam_fprobe(dbp, i, &fp->mpf, QAM_PROBE_MPF, 0)) != 0) {
if (ret == ENOENT)
continue;
return (ret);
@@ -494,10 +532,111 @@ again:
if (last < start) {
i = 1;
- stop = last;
start = 0;
goto again;
}
return (0);
}
+
+/*
+ * __qam_extent_names -- generate a list of extent files names.
+ *
+ * PUBLIC: int __qam_extent_names __P((DB_ENV *, char *, char ***));
+ */
+int
+__qam_extent_names(dbenv, name, namelistp)
+ DB_ENV *dbenv;
+ char *name;
+ char ***namelistp;
+{
+ DB *dbp;
+ QUEUE *qp;
+ QUEUE_FILELIST *filelist, *fp;
+ char buf[MAXPATHLEN], *dir, **cp, *freep;
+ int cnt, len, ret;
+
+ *namelistp = NULL;
+ filelist = NULL;
+ if ((ret = db_create(&dbp, dbenv, 0)) != 0)
+ return (ret);
+ if ((ret =
+ __db_open(dbp, NULL, name, NULL, DB_QUEUE, DB_RDONLY, 0)) != 0)
+ return (ret);
+ qp = dbp->q_internal;
+ if (qp->page_ext == 0)
+ goto done;
+
+ if ((ret = __qam_gen_filelist(dbp, &filelist)) != 0)
+ goto done;
+
+ if (filelist == NULL)
+ goto done;
+
+ cnt = 0;
+ for (fp = filelist; fp->mpf != NULL; fp++)
+ cnt++;
+ dir = ((QUEUE *)dbp->q_internal)->dir;
+ name = ((QUEUE *)dbp->q_internal)->name;
+
+ /* QUEUE_EXTENT contains extra chars, but add 6 anyway for the int. */
+ len = (u_int32_t)(cnt * (sizeof(**namelistp)
+ + strlen(QUEUE_EXTENT) + strlen(dir) + strlen(name) + 6));
+
+ if ((ret =
+ __os_malloc(dbp->dbenv, len, namelistp)) != 0)
+ goto done;
+ cp = *namelistp;
+ freep = (char *)(cp + cnt + 1);
+ for (fp = filelist; fp->mpf != NULL; fp++) {
+ snprintf(buf, sizeof(buf),
+ QUEUE_EXTENT, dir, PATH_SEPARATOR[0], name, fp->id);
+ len = (u_int32_t)strlen(buf);
+ *cp++ = freep;
+ strcpy(freep, buf);
+ freep += len + 1;
+ }
+ *cp = NULL;
+
+done:
+ if (filelist != NULL)
+ __os_free(dbp->dbenv, filelist);
+ (void)dbp->close(dbp, DB_NOSYNC);
+
+ return (ret);
+}
+
+/*
+ * __qam_exid --
+ * Generate a fileid for an extent based on the fileid of the main
+ * file. Since we do not log schema creates/deletes explicitly, the log
+ * never captures the fileid of an extent file. In order that masters and
+ * replicas have the same fileids (so they can explicitly delete them), we
+ * use computed fileids for the extent files of Queue files.
+ *
+ * An extent file id retains the low order 12 bytes of the file id and
+ * overwrites the dev/inode fields, placing a 0 in the inode field, and
+ * the extent number in the dev field.
+ *
+ * PUBLIC: void __qam_exid __P((DB *, u_int8_t *, u_int32_t));
+ */
+void
+__qam_exid(dbp, fidp, exnum)
+ DB *dbp;
+ u_int8_t *fidp;
+ u_int32_t exnum;
+{
+ int i;
+ u_int8_t *p;
+
+ /* Copy the fileid from the master. */
+ memcpy(fidp, dbp->fileid, DB_FILE_ID_LEN);
+
+ /* The first four bytes are the inode or the FileIndexLow; 0 it. */
+ for (i = sizeof(u_int32_t); i > 0; --i)
+ *fidp++ = 0;
+
+ /* The next four bytes are the dev/FileIndexHigh; insert the exnum . */
+ for (p = (u_int8_t *)&exnum, i = sizeof(u_int32_t); i > 0; --i)
+ *fidp++ = *p++;
+}
diff --git a/bdb/qam/qam_method.c b/bdb/qam/qam_method.c
index 1c94f4b8db0..5415fc5d00c 100644
--- a/bdb/qam/qam_method.c
+++ b/bdb/qam/qam_method.c
@@ -1,34 +1,32 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_method.c,v 11.17 2001/01/10 04:50:54 ubell Exp $";
+static const char revid[] = "$Id: qam_method.c,v 11.55 2002/08/26 17:52:19 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
+
#include <string.h>
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_int.h"
-#include "db_shash.h"
-#include "db_am.h"
-#include "qam.h"
-#include "db.h"
-#include "mp.h"
-#include "lock.h"
-#include "log.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_shash.h"
+#include "dbinc/db_am.h"
+#include "dbinc/fop.h"
+#include "dbinc/lock.h"
+#include "dbinc/qam.h"
+#include "dbinc/txn.h"
static int __qam_set_extentsize __P((DB *, u_int32_t));
-static int __qam_remove_callback __P((DB *, void *));
struct __qam_cookie {
DB_LSN lsn;
@@ -77,7 +75,8 @@ __qam_db_close(dbp)
int ret, t_ret;
ret = 0;
- t = dbp->q_internal;
+ if ((t = dbp->q_internal) == NULL)
+ return (0);
array = &t->array1;
again:
@@ -88,10 +87,10 @@ again:
mpf = mpfp->mpf;
mpfp->mpf = NULL;
if (mpf != NULL &&
- (t_ret = memp_fclose(mpf)) != 0 && ret == 0)
+ (t_ret = mpf->close(mpf, 0)) != 0 && ret == 0)
ret = t_ret;
}
- __os_free(array->mpfarray, 0);
+ __os_free(dbp->dbenv, array->mpfarray);
}
if (t->array2.n_extent != 0) {
array = &t->array2;
@@ -100,8 +99,8 @@ again:
}
if (t->path != NULL)
- __os_free(t->path, 0);
- __os_free(t, sizeof(QUEUE));
+ __os_free(dbp->dbenv, t->path);
+ __os_free(dbp->dbenv, t);
dbp->q_internal = NULL;
return (ret);
@@ -115,7 +114,7 @@ __qam_set_extentsize(dbp, extentsize)
DB_ILLEGAL_AFTER_OPEN(dbp, "set_extentsize");
if (extentsize < 1) {
- __db_err(dbp->dbenv, "Extent size must be at least 1.");
+ __db_err(dbp->dbenv, "Extent size must be at least 1");
return (EINVAL);
}
@@ -128,29 +127,35 @@ __qam_set_extentsize(dbp, extentsize)
* __db_prqueue --
* Print out a queue
*
- * PUBLIC: int __db_prqueue __P((DB *, u_int32_t));
+ * PUBLIC: int __db_prqueue __P((DB *, FILE *, u_int32_t));
*/
int
-__db_prqueue(dbp, flags)
+__db_prqueue(dbp, fp, flags)
DB *dbp;
+ FILE *fp;
u_int32_t flags;
{
+ DB_MPOOLFILE *mpf;
PAGE *h;
QMETA *meta;
db_pgno_t first, i, last, pg_ext, stop;
- int ret;
+ int ret, t_ret;
+
+ mpf = dbp->mpf;
/* Find out the page number of the last page in the database. */
i = PGNO_BASE_MD;
- if ((ret = memp_fget(dbp->mpf, &i, 0, &meta)) != 0)
+ if ((ret = mpf->get(mpf, &i, 0, &meta)) != 0)
return (ret);
first = QAM_RECNO_PAGE(dbp, meta->first_recno);
last = QAM_RECNO_PAGE(dbp, meta->cur_recno);
- if ((ret = __db_prpage(dbp, (PAGE *)meta, flags)) != 0)
- return (ret);
- if ((ret = memp_fput(dbp->mpf, meta, 0)) != 0)
+ ret = __db_prpage(dbp, (PAGE *)meta, fp, flags);
+ if ((t_ret = mpf->put(mpf, meta, 0)) != 0 && ret == 0)
+ ret = t_ret;
+
+ if (ret != 0)
return (ret);
i = first;
@@ -162,20 +167,20 @@ __db_prqueue(dbp, flags)
/* Dump each page. */
begin:
for (; i <= stop; ++i) {
- if ((ret = __qam_fget(dbp, &i, DB_MPOOL_EXTENT, &h)) != 0) {
+ if ((ret = __qam_fget(dbp, &i, 0, &h)) != 0) {
pg_ext = ((QUEUE *)dbp->q_internal)->page_ext;
if (pg_ext == 0) {
- if (ret == EINVAL && first == last)
+ if (ret == DB_PAGE_NOTFOUND && first == last)
return (0);
return (ret);
}
- if (ret == ENOENT || ret == EINVAL) {
+ if (ret == ENOENT || ret == DB_PAGE_NOTFOUND) {
i += pg_ext - ((i - 1) % pg_ext) - 1;
continue;
}
return (ret);
}
- (void)__db_prpage(dbp, h, flags);
+ (void)__db_prpage(dbp, h, fp, flags);
if ((ret = __qam_fput(dbp, i, h, 0)) != 0)
return (ret);
}
@@ -193,31 +198,31 @@ begin:
* __qam_remove
* Remove method for a Queue.
*
- * PUBLIC: int __qam_remove __P((DB *, const char *,
- * PUBLIC: const char *, DB_LSN *, int (**)(DB *, void*), void **));
+ * PUBLIC: int __qam_remove __P((DB *,
+ * PUBLIC: DB_TXN *, const char *, const char *, DB_LSN *));
*/
int
-__qam_remove(dbp, name, subdb, lsnp, callbackp, cookiep)
+__qam_remove(dbp, txn, name, subdb, lsnp)
DB *dbp;
+ DB_TXN *txn;
const char *name, *subdb;
DB_LSN *lsnp;
- int (**callbackp) __P((DB *, void *));
- void **cookiep;
{
- DBT namedbt;
DB_ENV *dbenv;
- DB_LSN lsn;
+ DB *tmpdbp;
MPFARRAY *ap;
QUEUE *qp;
- int ret;
- char *backup, buf[256], *real_back, *real_name;
QUEUE_FILELIST *filelist, *fp;
- struct __qam_cookie *qam_cookie;
+ int ret, needclose, t_ret;
+ char buf[MAXPATHLEN];
+ u_int8_t fid[DB_FILE_ID_LEN];
+
+ COMPQUIET(lsnp, NULL);
dbenv = dbp->dbenv;
ret = 0;
- backup = real_back = real_name = NULL;
filelist = NULL;
+ needclose = 0;
PANIC_CHECK(dbenv);
@@ -226,148 +231,86 @@ __qam_remove(dbp, name, subdb, lsnp, callbackp, cookiep)
*/
if (subdb != NULL) {
__db_err(dbenv,
- "Queue does not support multiple databases per file.");
+ "Queue does not support multiple databases per file");
ret = EINVAL;
- goto done;
+ goto err;
+ }
+
+ /*
+ * Since regular remove no longer opens the database, we may have
+ * to do it here.
+ */
+ if (F_ISSET(dbp, DB_AM_OPEN_CALLED))
+ tmpdbp = dbp;
+ else {
+ if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0)
+ return (ret);
+ /*
+ * We need to make sure we don't self-deadlock, so give
+ * this dbp the same locker as the incoming one.
+ */
+ tmpdbp->lid = dbp->lid;
+
+ /*
+ * If this is a transactional dbp and the open fails, then
+ * the transactional abort will close the dbp. If it's not
+ * a transactional open, then we always have to close it
+ * even if the open fails. Once the open has succeeded,
+ * then we will always want to close it.
+ */
+ if (txn == NULL)
+ needclose = 1;
+ if ((ret = tmpdbp->open(tmpdbp,
+ txn, name, NULL, DB_QUEUE, 0, 0)) != 0)
+ goto err;
+ needclose = 1;
}
- qp = (QUEUE *)dbp->q_internal;
+ qp = (QUEUE *)tmpdbp->q_internal;
if (qp->page_ext != 0 &&
- (ret = __qam_gen_filelist(dbp, &filelist)) != 0)
- goto done;
+ (ret = __qam_gen_filelist(tmpdbp, &filelist)) != 0)
+ goto err;
if (filelist == NULL)
- goto done;
+ goto err;
for (fp = filelist; fp->mpf != NULL; fp++) {
- snprintf(buf,
- sizeof(buf), QUEUE_EXTENT, qp->dir, qp->name, fp->id);
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, buf, 0, NULL, &real_name)) != 0)
- goto done;
- if (LOGGING_ON(dbenv)) {
- memset(&namedbt, 0, sizeof(namedbt));
- namedbt.data = (char *)buf;
- namedbt.size = strlen(buf) + 1;
-
- if ((ret =
- __qam_delete_log(dbenv, dbp->open_txn,
- &lsn, DB_FLUSH, &namedbt, lsnp)) != 0) {
- __db_err(dbenv,
- "%s: %s", name, db_strerror(ret));
- goto done;
- }
- }
- (void)__memp_fremove(fp->mpf);
- if ((ret = memp_fclose(fp->mpf)) != 0)
- goto done;
+ snprintf(buf, sizeof(buf),
+ QUEUE_EXTENT, qp->dir, PATH_SEPARATOR[0], qp->name, fp->id);
+ if ((ret = fp->mpf->close(fp->mpf, DB_MPOOL_DISCARD)) != 0)
+ goto err;
if (qp->array2.n_extent == 0 || qp->array2.low_extent > fp->id)
ap = &qp->array1;
else
ap = &qp->array2;
ap->mpfarray[fp->id - ap->low_extent].mpf = NULL;
- /* Create name for backup file. */
- if (TXN_ON(dbenv)) {
- if ((ret = __db_backup_name(dbenv,
- buf, &backup, lsnp)) != 0)
- goto done;
- if ((ret = __db_appname(dbenv, DB_APP_DATA,
- NULL, backup, 0, NULL, &real_back)) != 0)
- goto done;
- if ((ret = __os_rename(dbenv,
- real_name, real_back)) != 0)
- goto done;
- __os_freestr(real_back);
- real_back = NULL;
- }
- else
- if ((ret = __os_unlink(dbenv, real_name)) != 0)
- goto done;
- __os_freestr(real_name);
- real_name = NULL;
- }
- if ((ret= __os_malloc(dbenv,
- sizeof(struct __qam_cookie), NULL, &qam_cookie)) != 0)
- goto done;
- qam_cookie->lsn = *lsnp;
- qam_cookie->filelist = filelist;
- *cookiep = qam_cookie;
- *callbackp = __qam_remove_callback;
-
-done:
- if (ret != 0 && filelist != NULL)
- __os_free(filelist, 0);
- if (real_back != NULL)
- __os_freestr(real_back);
- if (real_name != NULL)
- __os_freestr(real_name);
- if (backup != NULL)
- __os_freestr(backup);
-
- return (ret);
-}
-
-static int
-__qam_remove_callback(dbp, cookie)
- DB *dbp;
- void *cookie;
-{
- DB_ENV *dbenv;
- DB_LSN *lsnp;
- QUEUE *qp;
- QUEUE_FILELIST *filelist, *fp;
- char *backup, buf[256], *real_back;
- int ret;
-
- qp = (QUEUE *)dbp->q_internal;
- if (qp->page_ext == 0)
- return (__os_unlink(dbp->dbenv, cookie));
-
- dbenv = dbp->dbenv;
- lsnp = &((struct __qam_cookie *)cookie)->lsn;
- filelist = fp = ((struct __qam_cookie *)cookie)->filelist;
- real_back = backup = NULL;
- if ((ret =
- __db_backup_name(dbenv, qp->name, &backup, lsnp)) != 0)
- goto err;
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, backup, 0, NULL, &real_back)) != 0)
- goto err;
- if ((ret = __os_unlink(dbp->dbenv, real_back)) != 0)
- goto err;
-
- __os_freestr(backup);
- __os_freestr(real_back);
-
- if (fp == NULL)
- return (0);
-
- for (; fp->mpf != NULL; fp++) {
- snprintf(buf,
- sizeof(buf), QUEUE_EXTENT, qp->dir, qp->name, fp->id);
- real_back = backup = NULL;
- if ((ret = __db_backup_name(dbenv, buf, &backup, lsnp)) != 0)
- goto err;
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, backup, 0, NULL, &real_back)) != 0)
+ /* Take care of object reclamation. */
+ __qam_exid(tmpdbp, fid, fp->id);
+ if ((ret = __fop_remove(dbenv,
+ txn, fid, buf, DB_APP_DATA)) != 0)
goto err;
- ret = __os_unlink(dbenv, real_back);
- __os_freestr(real_back);
- __os_freestr(backup);
}
- __os_free(filelist, 0);
- __os_free(cookie, sizeof (struct __qam_cookie));
- return (0);
-
-err:
- if (backup != NULL)
- __os_freestr(backup);
-
- if (real_back != NULL)
- __os_freestr(real_back);
+err: if (filelist != NULL)
+ __os_free(dbenv, filelist);
+ if (needclose) {
+ /*
+ * Since we copied the lid from the dbp, we'd better not
+ * free it here.
+ */
+ tmpdbp->lid = DB_LOCK_INVALIDID;
+
+ /* We need to remove the lockevent we associated with this. */
+ if (txn != NULL)
+ __txn_remlock(dbenv,
+ txn, &tmpdbp->handle_lock, DB_LOCK_INVALIDID);
+
+ if ((t_ret =
+ __db_close_i(tmpdbp, txn, DB_NOSYNC)) != 0 && ret == 0)
+ ret = t_ret;
+ }
return (ret);
}
@@ -376,97 +319,95 @@ err:
* __qam_rename
* Rename method for Queue.
*
- * PUBLIC: int __qam_rename __P((DB *,
+ * PUBLIC: int __qam_rename __P((DB *, DB_TXN *,
* PUBLIC: const char *, const char *, const char *));
*/
int
-__qam_rename(dbp, filename, subdb, newname)
+__qam_rename(dbp, txn, filename, subdb, newname)
DB *dbp;
+ DB_TXN *txn;
const char *filename, *subdb, *newname;
{
- DBT namedbt, newnamedbt;
DB_ENV *dbenv;
- DB_LSN newlsn;
+ DB *tmpdbp;
MPFARRAY *ap;
QUEUE *qp;
QUEUE_FILELIST *fp, *filelist;
- char buf[256], nbuf[256], *namep, *real_name, *real_newname;
- int ret;
+ char buf[MAXPATHLEN], nbuf[MAXPATHLEN];
+ char *namep;
+ int ret, needclose, t_ret;
+ u_int8_t fid[DB_FILE_ID_LEN], *fidp;
dbenv = dbp->dbenv;
ret = 0;
- real_name = real_newname = NULL;
filelist = NULL;
-
- qp = (QUEUE *)dbp->q_internal;
+ needclose = 0;
if (subdb != NULL) {
__db_err(dbenv,
- "Queue does not support multiple databases per file.");
+ "Queue does not support multiple databases per file");
ret = EINVAL;
goto err;
}
+
+ /*
+ * Since regular rename no longer opens the database, we may have
+ * to do it here.
+ */
+ if (F_ISSET(dbp, DB_AM_OPEN_CALLED))
+ tmpdbp = dbp;
+ else {
+ if ((ret = db_create(&tmpdbp, dbenv, 0)) != 0)
+ return (ret);
+ /* Copy the incoming locker so we don't self-deadlock. */
+ tmpdbp->lid = dbp->lid;
+ needclose = 1;
+ if ((ret = tmpdbp->open(tmpdbp, txn, filename, NULL,
+ DB_QUEUE, 0, 0)) != 0)
+ goto err;
+ }
+
+ qp = (QUEUE *)tmpdbp->q_internal;
+
if (qp->page_ext != 0 &&
- (ret = __qam_gen_filelist(dbp, &filelist)) != 0)
+ (ret = __qam_gen_filelist(tmpdbp, &filelist)) != 0)
goto err;
if ((namep = __db_rpath(newname)) != NULL)
newname = namep + 1;
+ fidp = fid;
for (fp = filelist; fp != NULL && fp->mpf != NULL; fp++) {
- if ((ret = __memp_fremove(fp->mpf)) != 0)
- goto err;
- if ((ret = memp_fclose(fp->mpf)) != 0)
+ fp->mpf->get_fileid(fp->mpf, fidp);
+ if ((ret = fp->mpf->close(fp->mpf, DB_MPOOL_DISCARD)) != 0)
goto err;
if (qp->array2.n_extent == 0 || qp->array2.low_extent > fp->id)
ap = &qp->array1;
else
ap = &qp->array2;
ap->mpfarray[fp->id - ap->low_extent].mpf = NULL;
- snprintf(buf,
- sizeof(buf), QUEUE_EXTENT, qp->dir, qp->name, fp->id);
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, buf, 0, NULL, &real_name)) != 0)
- goto err;
- snprintf(nbuf,
- sizeof(nbuf), QUEUE_EXTENT, qp->dir, newname, fp->id);
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, nbuf, 0, NULL, &real_newname)) != 0)
+ snprintf(buf, sizeof(buf),
+ QUEUE_EXTENT, qp->dir, PATH_SEPARATOR[0], qp->name, fp->id);
+ snprintf(nbuf, sizeof(nbuf),
+ QUEUE_EXTENT, qp->dir, PATH_SEPARATOR[0], newname, fp->id);
+ if ((ret = __fop_rename(dbenv,
+ txn, buf, nbuf, fidp, DB_APP_DATA)) != 0)
goto err;
- if (LOGGING_ON(dbenv)) {
- memset(&namedbt, 0, sizeof(namedbt));
- namedbt.data = (char *)buf;
- namedbt.size = strlen(buf) + 1;
-
- memset(&newnamedbt, 0, sizeof(namedbt));
- newnamedbt.data = (char *)nbuf;
- newnamedbt.size = strlen(nbuf) + 1;
-
- if ((ret =
- __qam_rename_log(dbenv,
- dbp->open_txn, &newlsn, 0,
- &namedbt, &newnamedbt)) != 0) {
- __db_err(dbenv, "%s: %s", filename, db_strerror(ret));
- goto err;
- }
-
- if ((ret = __log_filelist_update(dbenv, dbp,
- dbp->log_fileid, newname, NULL)) != 0)
- goto err;
- }
- if ((ret = __os_rename(dbenv, real_name, real_newname)) != 0)
- goto err;
- __os_freestr(real_name);
- __os_freestr(real_newname);
- real_name = real_newname = NULL;
}
-err:
- if (real_name != NULL)
- __os_freestr(real_name);
- if (real_newname != NULL)
- __os_freestr(real_newname);
- if (filelist != NULL)
- __os_free(filelist, 0);
+err: if (filelist != NULL)
+ __os_free(dbenv, filelist);
+ if (needclose) {
+ /* We copied this, so we mustn't free it. */
+ tmpdbp->lid = DB_LOCK_INVALIDID;
+ /* We need to remove the lockevent we associated with this. */
+ if (txn != NULL)
+ __txn_remlock(dbenv,
+ txn, &tmpdbp->handle_lock, DB_LOCK_INVALIDID);
+
+ if ((t_ret =
+ __db_close_i(tmpdbp, txn, DB_NOSYNC)) != 0 && ret == 0)
+ ret = t_ret;
+ }
return (ret);
}
diff --git a/bdb/qam/qam_open.c b/bdb/qam/qam_open.c
index 73346439fd6..efe4dfc540e 100644
--- a/bdb/qam/qam_open.c
+++ b/bdb/qam/qam_open.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_open.c,v 11.31 2000/12/20 17:59:29 ubell Exp $";
+static const char revid[] = "$Id: qam_open.c,v 11.55 2002/09/04 19:06:45 margo Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,174 +18,95 @@ static const char revid[] = "$Id: qam_open.c,v 11.31 2000/12/20 17:59:29 ubell E
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_shash.h"
-#include "db_swap.h"
-#include "db_am.h"
-#include "lock.h"
-#include "qam.h"
+#include "dbinc/crypto.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_shash.h"
+#include "dbinc/db_swap.h"
+#include "dbinc/db_am.h"
+#include "dbinc/lock.h"
+#include "dbinc/qam.h"
+#include "dbinc/fop.h"
+
+static int __qam_init_meta __P((DB *, QMETA *));
/*
* __qam_open
*
- * PUBLIC: int __qam_open __P((DB *, const char *, db_pgno_t, int, u_int32_t));
+ * PUBLIC: int __qam_open __P((DB *,
+ * PUBLIC: DB_TXN *, const char *, db_pgno_t, int, u_int32_t));
*/
int
-__qam_open(dbp, name, base_pgno, mode, flags)
+__qam_open(dbp, txn, name, base_pgno, mode, flags)
DB *dbp;
+ DB_TXN *txn;
const char *name;
db_pgno_t base_pgno;
int mode;
u_int32_t flags;
{
- QUEUE *t;
DBC *dbc;
+ DB_ENV *dbenv;
DB_LOCK metalock;
- DB_LSN orig_lsn;
+ DB_MPOOLFILE *mpf;
QMETA *qmeta;
- int locked;
+ QUEUE *t;
int ret, t_ret;
- ret = 0;
- locked = 0;
+ dbenv = dbp->dbenv;
+ mpf = dbp->mpf;
t = dbp->q_internal;
+ ret = 0;
+ qmeta = NULL;
- if (name == NULL && t->page_ext != 0) {
- __db_err(dbp->dbenv,
- "Extent size may not be specified for in-memory queue database.");
- return (EINVAL);
- }
/* Initialize the remaining fields/methods of the DB. */
- dbp->del = __qam_delete;
- dbp->put = __qam_put;
dbp->stat = __qam_stat;
dbp->sync = __qam_sync;
dbp->db_am_remove = __qam_remove;
dbp->db_am_rename = __qam_rename;
- metalock.off = LOCK_INVALID;
-
/*
* Get a cursor. If DB_CREATE is specified, we may be creating
* pages, and to do that safely in CDB we need a write cursor.
* In STD_LOCKING mode, we'll synchronize using the meta page
* lock instead.
*/
- if ((ret = dbp->cursor(dbp, dbp->open_txn,
- &dbc, LF_ISSET(DB_CREATE) && CDB_LOCKING(dbp->dbenv) ?
- DB_WRITECURSOR : 0)) != 0)
+ if ((ret = dbp->cursor(dbp, txn, &dbc,
+ LF_ISSET(DB_CREATE) && CDB_LOCKING(dbenv) ? DB_WRITECURSOR : 0))
+ != 0)
return (ret);
- /* Get, and optionally create the metadata page. */
+ /*
+ * Get the meta data page. It must exist, because creates of
+ * files/databases come in through the __qam_new_file interface
+ * and queue doesn't support subdatabases.
+ */
if ((ret =
__db_lget(dbc, 0, base_pgno, DB_LOCK_READ, 0, &metalock)) != 0)
goto err;
- if ((ret = memp_fget(
- dbp->mpf, &base_pgno, DB_MPOOL_CREATE, (PAGE **)&qmeta)) != 0)
+ if ((ret =
+ mpf->get(mpf, &base_pgno, 0, (PAGE **)&qmeta)) != 0)
goto err;
- /*
- * If the magic number is correct, we're not creating the tree.
- * Correct any fields that may not be right. Note, all of the
- * local flags were set by DB->open.
- */
-again: if (qmeta->dbmeta.magic == DB_QAMMAGIC) {
- t->re_pad = qmeta->re_pad;
- t->re_len = qmeta->re_len;
- t->rec_page = qmeta->rec_page;
- t->page_ext = qmeta->page_ext;
-
- (void)memp_fput(dbp->mpf, (PAGE *)qmeta, 0);
- goto done;
- }
-
- /* If we're doing CDB; we now have to get the write lock. */
- if (CDB_LOCKING(dbp->dbenv)) {
- DB_ASSERT(LF_ISSET(DB_CREATE));
- if ((ret = lock_get(dbp->dbenv, dbc->locker, DB_LOCK_UPGRADE,
- &dbc->lock_dbt, DB_LOCK_WRITE, &dbc->mylock)) != 0)
- goto err;
- }
-
- /*
- * If we are doing locking, relase the read lock
- * and get a write lock. We want to avoid deadlock.
- */
- if (locked == 0 && STD_LOCKING(dbc)) {
- if ((ret = __LPUT(dbc, metalock)) != 0)
- goto err;
- if ((ret = __db_lget(dbc,
- 0, base_pgno, DB_LOCK_WRITE, 0, &metalock)) != 0)
- goto err;
- locked = 1;
- goto again;
- }
- /* Initialize the tree structure metadata information. */
- orig_lsn = qmeta->dbmeta.lsn;
- memset(qmeta, 0, sizeof(QMETA));
- ZERO_LSN(qmeta->dbmeta.lsn);
- qmeta->dbmeta.pgno = base_pgno;
- qmeta->dbmeta.magic = DB_QAMMAGIC;
- qmeta->dbmeta.version = DB_QAMVERSION;
- qmeta->dbmeta.pagesize = dbp->pgsize;
- qmeta->dbmeta.type = P_QAMMETA;
- qmeta->re_pad = t->re_pad;
- qmeta->re_len = t->re_len;
- qmeta->rec_page = CALC_QAM_RECNO_PER_PAGE(dbp);
- qmeta->cur_recno = 1;
- qmeta->first_recno = 1;
- qmeta->page_ext = t->page_ext;
- t->rec_page = qmeta->rec_page;
- memcpy(qmeta->dbmeta.uid, dbp->fileid, DB_FILE_ID_LEN);
-
- /* Verify that we can fit at least one record per page. */
- if (QAM_RECNO_PER_PAGE(dbp) < 1) {
- __db_err(dbp->dbenv,
- "Record size of %lu too large for page size of %lu",
- (u_long)t->re_len, (u_long)dbp->pgsize);
- (void)memp_fput(dbp->mpf, (PAGE *)qmeta, 0);
+ /* If the magic number is incorrect, that's a fatal error. */
+ if (qmeta->dbmeta.magic != DB_QAMMAGIC) {
+ __db_err(dbenv, "%s: unexpected file type or format", name);
ret = EINVAL;
goto err;
}
- if ((ret = __db_log_page(dbp,
- name, &orig_lsn, base_pgno, (PAGE *)qmeta)) != 0)
- goto err;
-
- /* Release the metadata page. */
- if ((ret = memp_fput(dbp->mpf, (PAGE *)qmeta, DB_MPOOL_DIRTY)) != 0)
- goto err;
- DB_TEST_RECOVERY(dbp, DB_TEST_POSTLOG, ret, name);
-
- /*
- * Flush the metadata page to disk.
- *
- * !!!
- * It's not useful to return not-yet-flushed here -- convert it to
- * an error.
- */
- if ((ret = memp_fsync(dbp->mpf)) == DB_INCOMPLETE) {
- __db_err(dbp->dbenv, "Flush of metapage failed");
- ret = EINVAL;
- }
- DB_TEST_RECOVERY(dbp, DB_TEST_POSTSYNC, ret, name);
-
-done: t->q_meta = base_pgno;
- t->q_root = base_pgno + 1;
-
/* Setup information needed to open extents. */
- if (t->page_ext != 0) {
- t->finfo.pgcookie = &t->pgcookie;
- t->finfo.fileid = NULL;
- t->finfo.lsn_offset = 0;
+ t->page_ext = qmeta->page_ext;
+ if (t->page_ext != 0) {
t->pginfo.db_pagesize = dbp->pgsize;
- t->pginfo.needswap = F_ISSET(dbp, DB_AM_SWAP);
+ t->pginfo.flags =
+ F_ISSET(dbp, (DB_AM_CHKSUM | DB_AM_ENCRYPT | DB_AM_SWAP));
+ t->pginfo.type = dbp->type;
t->pgcookie.data = &t->pginfo;
t->pgcookie.size = sizeof(DB_PGINFO);
if ((ret = __os_strdup(dbp->dbenv, name, &t->path)) != 0)
- goto err;
+ return (ret);
t->dir = t->path;
if ((t->name = __db_rpath(t->path)) == NULL) {
t->name = t->path;
@@ -198,8 +119,22 @@ done: t->q_meta = base_pgno;
t->mode = mode;
}
-err:
-DB_TEST_RECOVERY_LABEL
+ if (name == NULL && t->page_ext != 0) {
+ __db_err(dbenv,
+ "Extent size may not be specified for in-memory queue database");
+ return (EINVAL);
+ }
+
+ t->re_pad = qmeta->re_pad;
+ t->re_len = qmeta->re_len;
+ t->rec_page = qmeta->rec_page;
+
+ t->q_meta = base_pgno;
+ t->q_root = base_pgno + 1;
+
+err: if (qmeta != NULL && (t_ret = mpf->put(mpf, qmeta, 0)) != 0 && ret == 0)
+ ret = t_ret;
+
/* Don't hold the meta page long term. */
(void)__LPUT(dbc, metalock);
@@ -225,6 +160,7 @@ __qam_metachk(dbp, name, qmeta)
int ret;
dbenv = dbp->dbenv;
+ ret = 0;
/*
* At this point, all we know is that the magic number is for a Queue.
@@ -241,6 +177,7 @@ __qam_metachk(dbp, name, qmeta)
name, (u_long)vers);
return (DB_OLD_VERSION);
case 3:
+ case 4:
break;
default:
__db_err(dbenv,
@@ -264,5 +201,131 @@ __qam_metachk(dbp, name, qmeta)
/* Copy the file's ID. */
memcpy(dbp->fileid, qmeta->dbmeta.uid, DB_FILE_ID_LEN);
+ /* Set up AM-specific methods that do not require an open. */
+ dbp->db_am_rename = __qam_rename;
+ dbp->db_am_remove = __qam_remove;
+
+ return (ret);
+}
+
+/*
+ * __qam_init_meta --
+ * Initialize the meta-data for a Queue database.
+ */
+static int
+__qam_init_meta(dbp, meta)
+ DB *dbp;
+ QMETA *meta;
+{
+ QUEUE *t;
+
+ t = dbp->q_internal;
+
+ memset(meta, 0, sizeof(QMETA));
+ LSN_NOT_LOGGED(meta->dbmeta.lsn);
+ meta->dbmeta.pgno = PGNO_BASE_MD;
+ meta->dbmeta.last_pgno = 0;
+ meta->dbmeta.magic = DB_QAMMAGIC;
+ meta->dbmeta.version = DB_QAMVERSION;
+ meta->dbmeta.pagesize = dbp->pgsize;
+ if (F_ISSET(dbp, DB_AM_CHKSUM))
+ FLD_SET(meta->dbmeta.metaflags, DBMETA_CHKSUM);
+ if (F_ISSET(dbp, DB_AM_ENCRYPT)) {
+ meta->dbmeta.encrypt_alg =
+ ((DB_CIPHER *)dbp->dbenv->crypto_handle)->alg;
+ DB_ASSERT(meta->dbmeta.encrypt_alg != 0);
+ meta->crypto_magic = meta->dbmeta.magic;
+ }
+ meta->dbmeta.type = P_QAMMETA;
+ meta->re_pad = t->re_pad;
+ meta->re_len = t->re_len;
+ meta->rec_page = CALC_QAM_RECNO_PER_PAGE(dbp);
+ meta->cur_recno = 1;
+ meta->first_recno = 1;
+ meta->page_ext = t->page_ext;
+ t->rec_page = meta->rec_page;
+ memcpy(meta->dbmeta.uid, dbp->fileid, DB_FILE_ID_LEN);
+
+ /* Verify that we can fit at least one record per page. */
+ if (QAM_RECNO_PER_PAGE(dbp) < 1) {
+ __db_err(dbp->dbenv,
+ "Record size of %lu too large for page size of %lu",
+ (u_long)t->re_len, (u_long)dbp->pgsize);
+ return (EINVAL);
+ }
+
return (0);
}
+
+/*
+ * __qam_new_file --
+ * Create the necessary pages to begin a new queue database file.
+ *
+ * This code appears more complex than it is because of the two cases (named
+ * and unnamed). The way to read the code is that for each page being created,
+ * there are three parts: 1) a "get page" chunk (which either uses malloc'd
+ * memory or calls mpf->get), 2) the initialization, and 3) the "put page"
+ * chunk which either does a fop write or an mpf->put.
+ *
+ * PUBLIC: int __qam_new_file __P((DB *, DB_TXN *, DB_FH *, const char *));
+ */
+int
+__qam_new_file(dbp, txn, fhp, name)
+ DB *dbp;
+ DB_TXN *txn;
+ DB_FH *fhp;
+ const char *name;
+{
+ QMETA *meta;
+ DB_ENV *dbenv;
+ DB_MPOOLFILE *mpf;
+ DB_PGINFO pginfo;
+ DBT pdbt;
+ db_pgno_t pgno;
+ int ret;
+ void *buf;
+
+ dbenv = dbp->dbenv;
+ mpf = dbp->mpf;
+ buf = NULL;
+ meta = NULL;
+
+ /* Build meta-data page. */
+
+ if (name == NULL) {
+ pgno = PGNO_BASE_MD;
+ ret = mpf->get(mpf, &pgno, DB_MPOOL_CREATE, &meta);
+ } else {
+ ret = __os_calloc(dbp->dbenv, 1, dbp->pgsize, &buf);
+ meta = (QMETA *)buf;
+ }
+ if (ret != 0)
+ return (ret);
+
+ if ((ret = __qam_init_meta(dbp, meta)) != 0)
+ goto err;
+
+ if (name == NULL)
+ ret = mpf->put(mpf, meta, DB_MPOOL_DIRTY);
+ else {
+ pginfo.db_pagesize = dbp->pgsize;
+ pginfo.flags =
+ F_ISSET(dbp, (DB_AM_CHKSUM | DB_AM_ENCRYPT | DB_AM_SWAP));
+ pginfo.type = DB_QUEUE;
+ pdbt.data = &pginfo;
+ pdbt.size = sizeof(pginfo);
+ if ((ret = __db_pgout(dbenv, PGNO_BASE_MD, meta, &pdbt)) != 0)
+ goto err;
+ ret = __fop_write(dbenv,
+ txn, name, DB_APP_DATA, fhp, 0, buf, dbp->pgsize, 1);
+ }
+ if (ret != 0)
+ goto err;
+ meta = NULL;
+
+err: if (name != NULL)
+ __os_free(dbenv, buf);
+ else if (meta != NULL)
+ (void)mpf->put(mpf, meta, 0);
+ return (ret);
+}
diff --git a/bdb/qam/qam_rec.c b/bdb/qam/qam_rec.c
index 4d330f58651..2c0f1227752 100644
--- a/bdb/qam/qam_rec.c
+++ b/bdb/qam/qam_rec.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_rec.c,v 11.34 2001/01/19 18:01:59 bostic Exp $";
+static const char revid[] = "$Id: qam_rec.c,v 11.69 2002/08/06 06:17:10 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,91 +18,12 @@ static const char revid[] = "$Id: qam_rec.c,v 11.34 2001/01/19 18:01:59 bostic E
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_shash.h"
-#include "lock.h"
-#include "db_am.h"
-#include "qam.h"
-#include "log.h"
-
-/*
- * __qam_inc_recover --
- * Recovery function for inc.
- *
- * PUBLIC: int __qam_inc_recover __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- */
-int
-__qam_inc_recover(dbenv, dbtp, lsnp, op, info)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops op;
- void *info;
-{
- __qam_inc_args *argp;
- DB *file_dbp;
- DBC *dbc;
- DB_LOCK lock;
- DB_MPOOLFILE *mpf;
- QMETA *meta;
- db_pgno_t metapg;
- int cmp_p, modified, ret;
-
- COMPQUIET(info, NULL);
- REC_PRINT(__qam_inc_print);
- REC_INTRO(__qam_inc_read, 1);
-
- metapg = ((QUEUE *)file_dbp->q_internal)->q_meta;
-
- if ((ret = __db_lget(dbc,
- LCK_ROLLBACK, metapg, DB_LOCK_WRITE, 0, &lock)) != 0)
- goto done;
- if ((ret = memp_fget(mpf, &metapg, 0, &meta)) != 0) {
- if (DB_REDO(op)) {
- if ((ret = memp_fget(mpf,
- &metapg, DB_MPOOL_CREATE, &meta)) != 0) {
- (void)__LPUT(dbc, lock);
- goto out;
- }
- meta->dbmeta.pgno = metapg;
- meta->dbmeta.type = P_QAMMETA;
-
- } else {
- *lsnp = argp->prev_lsn;
- ret = 0;
- (void)__LPUT(dbc, lock);
- goto out;
- }
- }
-
- modified = 0;
- cmp_p = log_compare(&LSN(meta), &argp->lsn);
- CHECK_LSN(op, cmp_p, &LSN(meta), &argp->lsn);
-
- /*
- * The cur_recno never goes backwards. It is a point of
- * contention among appenders. If one fails cur_recno will
- * most likely be beyond that one when it aborts.
- * We move it ahead on either an abort or a commit
- * and make the LSN reflect that fact.
- */
- if (cmp_p == 0) {
- modified = 1;
- meta->cur_recno++;
- if (meta->cur_recno == RECNO_OOB)
- meta->cur_recno++;
- meta->dbmeta.lsn = *lsnp;
- }
- if ((ret = memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)))
- goto out;
-
- (void)__LPUT(dbc, lock);
-
-done: *lsnp = argp->prev_lsn;
- ret = 0;
-
-out: REC_CLOSE;
-}
+#include "dbinc/db_page.h"
+#include "dbinc/db_shash.h"
+#include "dbinc/db_am.h"
+#include "dbinc/lock.h"
+#include "dbinc/log.h"
+#include "dbinc/qam.h"
/*
* __qam_incfirst_recover --
@@ -138,9 +59,9 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
if ((ret = __db_lget(dbc,
LCK_ROLLBACK, metapg, DB_LOCK_WRITE, 0, &lock)) != 0)
goto done;
- if ((ret = memp_fget(mpf, &metapg, 0, &meta)) != 0) {
+ if ((ret = mpf->get(mpf, &metapg, 0, &meta)) != 0) {
if (DB_REDO(op)) {
- if ((ret = memp_fget(mpf,
+ if ((ret = mpf->get(mpf,
&metapg, DB_MPOOL_CREATE, &meta)) != 0) {
(void)__LPUT(dbc, lock);
goto out;
@@ -178,11 +99,11 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
cp = (QUEUE_CURSOR *)dbc->internal;
if (meta->first_recno == RECNO_OOB)
meta->first_recno++;
- while (meta->first_recno != meta->cur_recno
- && !QAM_BEFORE_FIRST(meta, argp->recno + 1)) {
+ while (meta->first_recno != meta->cur_recno &&
+ !QAM_BEFORE_FIRST(meta, argp->recno + 1)) {
if ((ret = __qam_position(dbc,
&meta->first_recno, QAM_READ, &exact)) != 0)
- goto out;
+ goto err;
if (cp->page != NULL)
__qam_fput(file_dbp, cp->pgno, cp->page, 0);
@@ -192,7 +113,7 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
rec_ext != 0 && meta->first_recno % rec_ext == 0)
if ((ret =
__qam_fremove(file_dbp, cp->pgno)) != 0)
- goto out;
+ goto err;
meta->first_recno++;
if (meta->first_recno == RECNO_OOB)
meta->first_recno++;
@@ -200,14 +121,19 @@ __qam_incfirst_recover(dbenv, dbtp, lsnp, op, info)
}
}
- if ((ret = memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)))
- goto out;
+ if ((ret = mpf->put(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)) != 0)
+ goto err1;
(void)__LPUT(dbc, lock);
done: *lsnp = argp->prev_lsn;
ret = 0;
+ if (0) {
+err: (void)mpf->put(mpf, meta, 0);
+err1: (void)__LPUT(dbc, lock);
+ }
+
out: REC_CLOSE;
}
@@ -233,7 +159,7 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
DB_MPOOLFILE *mpf;
QMETA *meta;
db_pgno_t metapg;
- int cmp_p, modified, ret;
+ int cmp_n, cmp_p, modified, ret;
COMPQUIET(info, NULL);
REC_PRINT(__qam_mvptr_print);
@@ -244,9 +170,9 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
if ((ret = __db_lget(dbc,
LCK_ROLLBACK, metapg, DB_LOCK_WRITE, 0, &lock)) != 0)
goto done;
- if ((ret = memp_fget(mpf, &metapg, 0, &meta)) != 0) {
+ if ((ret = mpf->get(mpf, &metapg, 0, &meta)) != 0) {
if (DB_REDO(op)) {
- if ((ret = memp_fget(mpf,
+ if ((ret = mpf->get(mpf,
&metapg, DB_MPOOL_CREATE, &meta)) != 0) {
(void)__LPUT(dbc, lock);
goto out;
@@ -262,13 +188,24 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
}
modified = 0;
- cmp_p = log_compare(&meta->dbmeta.lsn, &argp->metalsn);
+ cmp_n = log_compare(lsnp, &LSN(meta));
+ cmp_p = log_compare(&LSN(meta), &argp->metalsn);
/*
- * We never undo a movement of one of the pointers.
- * Just move them along regardless of abort/commit.
+ * Under normal circumstances, we never undo a movement of one of
+ * the pointers. Just move them along regardless of abort/commit.
+ *
+ * If we're undoing a truncate, we need to reset the pointers to
+ * their state before the truncate.
*/
- if (cmp_p == 0) {
+ if (DB_UNDO(op) && (argp->opcode & QAM_TRUNCATE)) {
+ if (cmp_n == 0) {
+ meta->first_recno = argp->old_first;
+ meta->cur_recno = argp->old_cur;
+ modified = 1;
+ meta->dbmeta.lsn = argp->metalsn;
+ }
+ } else if (cmp_p == 0) {
if (argp->opcode & QAM_SETFIRST)
meta->first_recno = argp->new_first;
@@ -279,7 +216,7 @@ __qam_mvptr_recover(dbenv, dbtp, lsnp, op, info)
meta->dbmeta.lsn = *lsnp;
}
- if ((ret = memp_fput(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)))
+ if ((ret = mpf->put(mpf, meta, modified ? DB_MPOOL_DIRTY : 0)) != 0)
goto out;
(void)__LPUT(dbc, lock);
@@ -289,6 +226,7 @@ done: *lsnp = argp->prev_lsn;
out: REC_CLOSE;
}
+
/*
* __qam_del_recover --
* Recovery function for del.
@@ -321,7 +259,7 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
REC_INTRO(__qam_del_read, 1);
if ((ret = __qam_fget(file_dbp,
- &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
+ &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
goto out;
modified = 0;
@@ -338,20 +276,20 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
metapg = ((QUEUE *)file_dbp->q_internal)->q_meta;
if ((ret = __db_lget(dbc,
LCK_ROLLBACK, metapg, DB_LOCK_WRITE, 0, &lock)) != 0)
- return (ret);
- if ((ret = memp_fget(file_dbp->mpf, &metapg, 0, &meta)) != 0) {
+ goto err;
+ if ((ret = mpf->get(mpf, &metapg, 0, &meta)) != 0) {
(void)__LPUT(dbc, lock);
- goto done;
+ goto err;
}
if (meta->first_recno == RECNO_OOB ||
- (QAM_BEFORE_FIRST(meta, argp->recno)
- && (meta->first_recno <= meta->cur_recno
- || meta->first_recno -
+ (QAM_BEFORE_FIRST(meta, argp->recno) &&
+ (meta->first_recno <= meta->cur_recno ||
+ meta->first_recno -
argp->recno < argp->recno - meta->cur_recno))) {
meta->first_recno = argp->recno;
- (void)memp_fput(file_dbp->mpf, meta, DB_MPOOL_DIRTY);
+ (void)mpf->put(mpf, meta, DB_MPOOL_DIRTY);
} else
- (void)memp_fput(file_dbp->mpf, meta, 0);
+ (void)mpf->put(mpf, meta, 0);
(void)__LPUT(dbc, lock);
/* Need to undo delete - mark the record as present */
@@ -366,7 +304,7 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
* is harmless in queue except when we're determining
* what we need to roll forward during recovery. [#2588]
*/
- if (op == DB_TXN_BACKWARD_ROLL && cmp_n < 0)
+ if (op == DB_TXN_BACKWARD_ROLL && cmp_n <= 0)
LSN(pagep) = argp->lsn;
modified = 1;
} else if (cmp_n > 0 && DB_REDO(op)) {
@@ -377,14 +315,18 @@ __qam_del_recover(dbenv, dbtp, lsnp, op, info)
modified = 1;
}
if ((ret = __qam_fput(file_dbp,
- argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)))
+ argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)) != 0)
goto out;
done: *lsnp = argp->prev_lsn;
ret = 0;
+ if (0) {
+err: (void)__qam_fput(file_dbp, argp->pgno, pagep, 0);
+ }
out: REC_CLOSE;
}
+
/*
* __qam_delext_recover --
* Recovery function for del in an extent based queue.
@@ -415,9 +357,19 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
REC_PRINT(__qam_delext_print);
REC_INTRO(__qam_delext_read, 1);
- if ((ret = __qam_fget(file_dbp,
- &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
- goto out;
+ if ((ret = __qam_fget(file_dbp, &argp->pgno, 0, &pagep)) != 0) {
+ if (ret != DB_PAGE_NOTFOUND && ret != ENOENT)
+ goto out;
+ /*
+ * If we are redoing a delete and the page is not there
+ * we are done.
+ */
+ if (DB_REDO(op))
+ goto done;
+ if ((ret = __qam_fget(file_dbp,
+ &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
+ goto out;
+ }
modified = 0;
if (pagep->pgno == PGNO_INVALID) {
@@ -433,25 +385,25 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
metapg = ((QUEUE *)file_dbp->q_internal)->q_meta;
if ((ret = __db_lget(dbc,
LCK_ROLLBACK, metapg, DB_LOCK_WRITE, 0, &lock)) != 0)
- return (ret);
- if ((ret = memp_fget(file_dbp->mpf, &metapg, 0, &meta)) != 0) {
+ goto err;
+ if ((ret = mpf->get(mpf, &metapg, 0, &meta)) != 0) {
(void)__LPUT(dbc, lock);
- goto done;
+ goto err;
}
if (meta->first_recno == RECNO_OOB ||
- (QAM_BEFORE_FIRST(meta, argp->recno)
- && (meta->first_recno <= meta->cur_recno
- || meta->first_recno -
+ (QAM_BEFORE_FIRST(meta, argp->recno) &&
+ (meta->first_recno <= meta->cur_recno ||
+ meta->first_recno -
argp->recno < argp->recno - meta->cur_recno))) {
meta->first_recno = argp->recno;
- (void)memp_fput(file_dbp->mpf, meta, DB_MPOOL_DIRTY);
+ (void)mpf->put(mpf, meta, DB_MPOOL_DIRTY);
} else
- (void)memp_fput(file_dbp->mpf, meta, 0);
+ (void)mpf->put(mpf, meta, 0);
(void)__LPUT(dbc, lock);
if ((ret = __qam_pitem(dbc, pagep,
argp->indx, argp->recno, &argp->data)) != 0)
- goto done;
+ goto err;
/*
* Move the LSN back to this point; do not move it forward.
@@ -461,7 +413,7 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
* is harmless in queue except when we're determining
* what we need to roll forward during recovery. [#2588]
*/
- if (op == DB_TXN_BACKWARD_ROLL && cmp_n < 0)
+ if (op == DB_TXN_BACKWARD_ROLL && cmp_n <= 0)
LSN(pagep) = argp->lsn;
modified = 1;
} else if (cmp_n > 0 && DB_REDO(op)) {
@@ -472,12 +424,15 @@ __qam_delext_recover(dbenv, dbtp, lsnp, op, info)
modified = 1;
}
if ((ret = __qam_fput(file_dbp,
- argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)))
+ argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)) != 0)
goto out;
done: *lsnp = argp->prev_lsn;
ret = 0;
+ if (0) {
+err: (void)__qam_fput(file_dbp, argp->pgno, pagep, 0);
+ }
out: REC_CLOSE;
}
@@ -485,7 +440,8 @@ out: REC_CLOSE;
* __qam_add_recover --
* Recovery function for add.
*
- * PUBLIC: int __qam_add_recover __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
+ * PUBLIC: int __qam_add_recover
+ * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
*/
int
__qam_add_recover(dbenv, dbtp, lsnp, op, info)
@@ -503,16 +459,26 @@ __qam_add_recover(dbenv, dbtp, lsnp, op, info)
QMETA *meta;
QPAGE *pagep;
db_pgno_t metapg;
- int cmp_n, modified, ret;
+ int cmp_n, meta_dirty, modified, ret;
COMPQUIET(info, NULL);
REC_PRINT(__qam_add_print);
REC_INTRO(__qam_add_read, 1);
modified = 0;
- if ((ret = __qam_fget(file_dbp,
- &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
- goto out;
+ if ((ret = __qam_fget(file_dbp, &argp->pgno, 0, &pagep)) != 0) {
+ if (ret != DB_PAGE_NOTFOUND && ret != ENOENT)
+ goto out;
+ /*
+ * If we are undoing an append and the page is not there
+ * we are done.
+ */
+ if (DB_UNDO(op))
+ goto done;
+ if ((ret = __qam_fget(file_dbp,
+ &argp->pgno, DB_MPOOL_CREATE, &pagep)) != 0)
+ goto out;
+ }
if (pagep->pgno == PGNO_INVALID) {
pagep->pgno = argp->pgno;
@@ -522,25 +488,36 @@ __qam_add_recover(dbenv, dbtp, lsnp, op, info)
cmp_n = log_compare(lsnp, &LSN(pagep));
- if (cmp_n > 0 && DB_REDO(op)) {
- /* Need to redo add - put the record on page */
- if ((ret = __qam_pitem(dbc, pagep, argp->indx, argp->recno,
- &argp->data)) != 0)
- goto err;
- LSN(pagep) = *lsnp;
- modified = 1;
- /* Make sure first pointer includes this record. */
+ if (DB_REDO(op)) {
+ /* Fix meta-data page. */
metapg = ((QUEUE *)file_dbp->q_internal)->q_meta;
- if ((ret = memp_fget(mpf, &metapg, 0, &meta)) != 0)
+ if ((ret = mpf->get(mpf, &metapg, 0, &meta)) != 0)
goto err;
+ meta_dirty = 0;
if (QAM_BEFORE_FIRST(meta, argp->recno)) {
meta->first_recno = argp->recno;
- if ((ret = memp_fput(mpf, meta, DB_MPOOL_DIRTY)) != 0)
- goto err;
- } else
- if ((ret = memp_fput(mpf, meta, 0)) != 0)
- goto err;
+ meta_dirty = 1;
+ }
+ if (argp->recno == meta->cur_recno ||
+ QAM_AFTER_CURRENT(meta, argp->recno)) {
+ meta->cur_recno = argp->recno + 1;
+ meta_dirty = 1;
+ }
+ if ((ret =
+ mpf->put(mpf, meta, meta_dirty? DB_MPOOL_DIRTY : 0)) != 0)
+ goto err;
+ /* Now update the actual page if necessary. */
+ if (cmp_n > 0) {
+ /* Need to redo add - put the record on page */
+ if ((ret = __qam_pitem(dbc,
+ pagep, argp->indx, argp->recno, &argp->data)) != 0)
+ goto err;
+ LSN(pagep) = *lsnp;
+ modified = 1;
+ /* Make sure pointers include this record. */
+ metapg = ((QUEUE *)file_dbp->q_internal)->q_meta;
+ }
} else if (DB_UNDO(op)) {
/*
* Need to undo add
@@ -572,161 +549,20 @@ __qam_add_recover(dbenv, dbtp, lsnp, op, info)
* is harmless in queue except when we're determining
* what we need to roll forward during recovery. [#2588]
*/
- if (op == DB_TXN_BACKWARD_ROLL && cmp_n < 0)
+ if (op == DB_TXN_BACKWARD_ROLL && cmp_n <= 0)
LSN(pagep) = argp->lsn;
}
-err: if ((ret = __qam_fput(file_dbp,
- argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)))
+ if ((ret = __qam_fput(file_dbp,
+ argp->pgno, pagep, modified ? DB_MPOOL_DIRTY : 0)) != 0)
goto out;
done: *lsnp = argp->prev_lsn;
ret = 0;
-out: REC_CLOSE;
-}
-/*
- * __qam_delete_recover --
- * Recovery function for delete of an extent.
- *
- * PUBLIC: int __qam_delete_recover
- * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- */
-int
-__qam_delete_recover(dbenv, dbtp, lsnp, op, info)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops op;
- void *info;
-{
- __qam_delete_args *argp;
- int ret;
- char *backup, *real_back, *real_name;
-
- COMPQUIET(info, NULL);
-
- REC_PRINT(__qam_delete_print);
-
- backup = real_back = real_name = NULL;
- if ((ret = __qam_delete_read(dbenv, dbtp->data, &argp)) != 0)
- goto out;
-
- if (DB_REDO(op)) {
- /*
- * On a recovery, as we recreate what was going on, we
- * recreate the creation of the file. And so, even though
- * it committed, we need to delete it. Try to delete it,
- * but it is not an error if that delete fails.
- */
- if ((ret = __db_appname(dbenv, DB_APP_DATA,
- NULL, argp->name.data, 0, NULL, &real_name)) != 0)
- goto out;
- if (__os_exists(real_name, NULL) == 0) {
- if ((ret = __os_unlink(dbenv, real_name)) != 0)
- goto out;
- }
- } else if (DB_UNDO(op)) {
- /*
- * Trying to undo. File may or may not have been deleted.
- * Try to move the backup to the original. If the backup
- * exists, then this is right. If it doesn't exist, then
- * nothing will happen and that's OK.
- */
- if ((ret = __db_backup_name(dbenv, argp->name.data,
- &backup, &argp->lsn)) != 0)
- goto out;
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, backup, 0, NULL, &real_back)) != 0)
- goto out;
- if ((ret = __db_appname(dbenv, DB_APP_DATA,
- NULL, argp->name.data, 0, NULL, &real_name)) != 0)
- goto out;
- if (__os_exists(real_back, NULL) == 0)
- if ((ret =
- __os_rename(dbenv, real_back, real_name)) != 0)
- goto out;
- }
- *lsnp = argp->prev_lsn;
- ret = 0;
-
-out: if (argp != NULL)
- __os_free(argp, 0);
- if (backup != NULL)
- __os_freestr(backup);
- if (real_back != NULL)
- __os_freestr(real_back);
- if (real_name != NULL)
- __os_freestr(real_name);
- return (ret);
-}
-/*
- * __qam_rename_recover --
- * Recovery function for rename.
- *
- * PUBLIC: int __qam_rename_recover
- * PUBLIC: __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
- */
-int
-__qam_rename_recover(dbenv, dbtp, lsnp, op, info)
- DB_ENV *dbenv;
- DBT *dbtp;
- DB_LSN *lsnp;
- db_recops op;
- void *info;
-{
- __qam_rename_args *argp;
- char *new_name, *real_name;
- int ret;
-
- COMPQUIET(info, NULL);
-
- REC_PRINT(__qam_rename_print);
-
- new_name = real_name = NULL;
-
- if ((ret = __qam_rename_read(dbenv, dbtp->data, &argp)) != 0)
- goto out;
-
- if (DB_REDO(op)) {
- if ((ret = __db_appname(dbenv, DB_APP_DATA,
- NULL, argp->name.data, 0, NULL, &real_name)) != 0)
- goto out;
- if (__os_exists(real_name, NULL) == 0) {
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, argp->newname.data,
- 0, NULL, &new_name)) != 0)
- goto out;
- if ((ret = __os_rename(dbenv,
- real_name, new_name)) != 0)
- goto out;
- }
- } else {
- if ((ret = __db_appname(dbenv, DB_APP_DATA,
- NULL, argp->newname.data, 0, NULL, &new_name)) != 0)
- goto out;
- if (__os_exists(new_name, NULL) == 0) {
- if ((ret = __db_appname(dbenv,
- DB_APP_DATA, NULL, argp->name.data,
- 0, NULL, &real_name)) != 0)
- goto out;
- if ((ret = __os_rename(dbenv,
- new_name, real_name)) != 0)
- goto out;
- }
+ if (0) {
+err: (void)__qam_fput(file_dbp, argp->pgno, pagep, 0);
}
- *lsnp = argp->prev_lsn;
- ret = 0;
-
-out: if (argp != NULL)
- __os_free(argp, 0);
-
- if (new_name != NULL)
- __os_free(new_name, 0);
-
- if (real_name != NULL)
- __os_free(real_name, 0);
-
- return (ret);
+out: REC_CLOSE;
}
diff --git a/bdb/qam/qam_stat.c b/bdb/qam/qam_stat.c
index 865f477c1eb..57c67da4292 100644
--- a/bdb/qam/qam_stat.c
+++ b/bdb/qam/qam_stat.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_stat.c,v 11.16 2001/01/10 04:50:54 ubell Exp $";
+static const char revid[] = "$Id: qam_stat.c,v 11.32 2002/05/11 13:40:11 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,32 +18,33 @@ static const char revid[] = "$Id: qam_stat.c,v 11.16 2001/01/10 04:50:54 ubell E
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_shash.h"
-#include "db_am.h"
-#include "lock.h"
-#include "qam.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_shash.h"
+#include "dbinc/db_am.h"
+#include "dbinc/lock.h"
+#include "dbinc/log.h"
+#include "dbinc/qam.h"
/*
* __qam_stat --
* Gather/print the qam statistics
*
- * PUBLIC: int __qam_stat __P((DB *, void *, void *(*)(size_t), u_int32_t));
+ * PUBLIC: int __qam_stat __P((DB *, void *, u_int32_t));
*/
int
-__qam_stat(dbp, spp, db_malloc, flags)
+__qam_stat(dbp, spp, flags)
DB *dbp;
void *spp;
- void *(*db_malloc) __P((size_t));
u_int32_t flags;
{
- QUEUE *t;
DBC *dbc;
DB_LOCK lock;
+ DB_MPOOLFILE *mpf;
DB_QUEUE_STAT *sp;
PAGE *h;
QAMDATA *qp, *ep;
QMETA *meta;
+ QUEUE *t;
db_indx_t indx;
db_pgno_t first, last, pgno, pg_ext, stop;
u_int32_t re_len;
@@ -52,9 +53,10 @@ __qam_stat(dbp, spp, db_malloc, flags)
PANIC_CHECK(dbp->dbenv);
DB_ILLEGAL_BEFORE_OPEN(dbp, "DB->stat");
- t = dbp->q_internal;
+ LOCK_INIT(lock);
+ mpf = dbp->mpf;
sp = NULL;
- lock.off = LOCK_INVALID;
+ t = dbp->q_internal;
/* Check for invalid flags. */
if ((ret = __db_statchk(dbp, flags)) != 0)
@@ -70,35 +72,29 @@ __qam_stat(dbp, spp, db_malloc, flags)
DEBUG_LWRITE(dbc, NULL, "qam_stat", NULL, NULL, flags);
/* Allocate and clear the structure. */
- if ((ret = __os_malloc(dbp->dbenv, sizeof(*sp), db_malloc, &sp)) != 0)
+ if ((ret = __os_umalloc(dbp->dbenv, sizeof(*sp), &sp)) != 0)
goto err;
memset(sp, 0, sizeof(*sp));
re_len = ((QUEUE *)dbp->q_internal)->re_len;
- if (flags == DB_CACHED_COUNTS) {
- if ((ret = __db_lget(dbc,
- 0, t->q_meta, DB_LOCK_READ, 0, &lock)) != 0)
- goto err;
- if ((ret =
- memp_fget(dbp->mpf, &t->q_meta, 0, (PAGE **)&meta)) != 0)
- goto err;
- sp->qs_nkeys = meta->dbmeta.key_count;
- sp->qs_ndata = meta->dbmeta.record_count;
-
- goto done;
- }
/* Determine the last page of the database. */
if ((ret = __db_lget(dbc,
0, t->q_meta, DB_LOCK_READ, 0, &lock)) != 0)
goto err;
- if ((ret = memp_fget(dbp->mpf, &t->q_meta, 0, (PAGE **)&meta)) != 0)
+ if ((ret = mpf->get(mpf, &t->q_meta, 0, (PAGE **)&meta)) != 0)
goto err;
+ if (flags == DB_FAST_STAT || flags == DB_CACHED_COUNTS) {
+ sp->qs_nkeys = meta->dbmeta.key_count;
+ sp->qs_ndata = meta->dbmeta.record_count;
+ goto meta_only;
+ }
+
first = QAM_RECNO_PAGE(dbp, meta->first_recno);
last = QAM_RECNO_PAGE(dbp, meta->cur_recno);
- if ((ret = memp_fput(dbp->mpf, meta, 0)) != 0)
+ if ((ret = mpf->put(mpf, meta, 0)) != 0)
goto err;
(void)__LPUT(dbc, lock);
@@ -114,20 +110,23 @@ begin:
/* Walk through the pages and count. */
for (; pgno <= stop; ++pgno) {
if ((ret =
- __db_lget(dbc,
- 0, pgno, DB_LOCK_READ, 0, &lock)) != 0)
+ __db_lget(dbc, 0, pgno, DB_LOCK_READ, 0, &lock)) != 0)
goto err;
- ret = __qam_fget(dbp, &pgno, DB_MPOOL_EXTENT, &h);
+ ret = __qam_fget(dbp, &pgno, 0, &h);
if (ret == ENOENT) {
pgno += pg_ext - 1;
continue;
}
- if (ret == EINVAL) {
+ if (ret == DB_PAGE_NOTFOUND) {
+ if (pg_ext == 0) {
+ if (pgno != stop && first != last)
+ goto err;
+ ret = 0;
+ break;
+ }
pgno += pg_ext - ((pgno - 1) % pg_ext) - 1;
continue;
}
- if (ret == EIO && first == last && pg_ext == 0)
- break;
if (ret != 0)
goto err;
@@ -147,6 +146,8 @@ begin:
goto err;
(void)__LPUT(dbc, lock);
}
+
+ (void)__LPUT(dbc, lock);
if (first > last) {
pgno = 1;
stop = last;
@@ -159,26 +160,28 @@ begin:
0, t->q_meta, F_ISSET(dbp, DB_AM_RDONLY) ?
DB_LOCK_READ : DB_LOCK_WRITE, 0, &lock)) != 0)
goto err;
- if ((ret = memp_fget(dbp->mpf, &t->q_meta, 0, (PAGE **)&meta)) != 0)
+ if ((ret = mpf->get(mpf, &t->q_meta, 0, (PAGE **)&meta)) != 0)
goto err;
+ if (!F_ISSET(dbp, DB_AM_RDONLY))
+ meta->dbmeta.key_count =
+ meta->dbmeta.record_count = sp->qs_ndata;
+ sp->qs_nkeys = sp->qs_ndata;
+
+meta_only:
/* Get the metadata fields. */
sp->qs_magic = meta->dbmeta.magic;
sp->qs_version = meta->dbmeta.version;
sp->qs_metaflags = meta->dbmeta.flags;
sp->qs_pagesize = meta->dbmeta.pagesize;
+ sp->qs_extentsize = meta->page_ext;
sp->qs_re_len = meta->re_len;
sp->qs_re_pad = meta->re_pad;
sp->qs_first_recno = meta->first_recno;
sp->qs_cur_recno = meta->cur_recno;
- sp->qs_nkeys = sp->qs_ndata;
- if (!F_ISSET(dbp, DB_AM_RDONLY))
- meta->dbmeta.key_count =
- meta->dbmeta.record_count = sp->qs_ndata;
-done:
/* Discard the meta-data page. */
- if ((ret = memp_fput(dbp->mpf,
+ if ((ret = mpf->put(mpf,
meta, F_ISSET(dbp, DB_AM_RDONLY) ? 0 : DB_MPOOL_DIRTY)) != 0)
goto err;
(void)__LPUT(dbc, lock);
@@ -188,11 +191,10 @@ done:
if (0) {
err: if (sp != NULL)
- __os_free(sp, sizeof(*sp));
+ __os_ufree(dbp->dbenv, sp);
}
- if (lock.off != LOCK_INVALID)
- (void)__LPUT(dbc, lock);
+ (void)__LPUT(dbc, lock);
if ((t_ret = dbc->c_close(dbc)) != 0 && ret == 0)
ret = t_ret;
diff --git a/bdb/qam/qam_upgrade.c b/bdb/qam/qam_upgrade.c
index f49bfe88d90..6bd79fc948a 100644
--- a/bdb/qam/qam_upgrade.c
+++ b/bdb/qam/qam_upgrade.c
@@ -1,13 +1,13 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_upgrade.c,v 11.7 2000/11/30 00:58:44 ubell Exp $";
+static const char revid[] = "$Id: qam_upgrade.c,v 11.12 2002/03/29 20:46:48 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -18,10 +18,7 @@ static const char revid[] = "$Id: qam_upgrade.c,v 11.7 2000/11/30 00:58:44 ubell
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_swap.h"
-#include "db_am.h"
-#include "db_upgrade.h"
+#include "dbinc/db_upgrade.h"
/*
* __qam_31_qammeta --
diff --git a/bdb/qam/qam_verify.c b/bdb/qam/qam_verify.c
index a9a467d6785..5b020c2c335 100644
--- a/bdb/qam/qam_verify.c
+++ b/bdb/qam/qam_verify.c
@@ -1,14 +1,14 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1999, 2000
+ * Copyright (c) 1999-2002
* Sleepycat Software. All rights reserved.
*/
#include "db_config.h"
#ifndef lint
-static const char revid[] = "$Id: qam_verify.c,v 1.17 2000/12/12 17:39:35 bostic Exp $";
+static const char revid[] = "$Id: qam_verify.c,v 1.30 2002/06/26 20:49:27 bostic Exp $";
#endif /* not lint */
#ifndef NO_SYSTEM_INCLUDES
@@ -17,10 +17,10 @@ static const char revid[] = "$Id: qam_verify.c,v 1.17 2000/12/12 17:39:35 bostic
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "db_verify.h"
-#include "qam.h"
-#include "db_ext.h"
+#include "dbinc/db_page.h"
+#include "dbinc/db_verify.h"
+#include "dbinc/qam.h"
+#include "dbinc/db_am.h"
/*
* __qam_vrfy_meta --
@@ -49,7 +49,9 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
* something very odd is going on.
*/
if (!F_ISSET(pip, VRFY_INCOMPLETE))
- EPRINT((dbp->dbenv, "Queue databases must be one-per-file."));
+ EPRINT((dbp->dbenv,
+ "Page %lu: queue databases must be one-per-file",
+ (u_long)pgno));
/*
* cur_recno/rec_page
@@ -59,8 +61,9 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
if (vdp->last_pgno > 0 && meta->cur_recno > 0 &&
meta->cur_recno - 1 > meta->rec_page * vdp->last_pgno) {
EPRINT((dbp->dbenv,
- "Current recno %lu references record past last page number %lu",
- meta->cur_recno, vdp->last_pgno));
+ "Page %lu: current recno %lu references record past last page number %lu",
+ (u_long)pgno,
+ (u_long)meta->cur_recno, (u_long)vdp->last_pgno));
isbad = 1;
}
@@ -69,10 +72,10 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
* return DB_VERIFY_FATAL
*/
if (ALIGN(meta->re_len + sizeof(QAMDATA) - 1, sizeof(u_int32_t)) *
- meta->rec_page + sizeof(QPAGE) > dbp->pgsize) {
+ meta->rec_page + QPAGE_SZ(dbp) > dbp->pgsize) {
EPRINT((dbp->dbenv,
- "Queue record length %lu impossibly high for page size and records per page",
- meta->re_len));
+ "Page %lu: queue record length %lu too high for page size and recs/page",
+ (u_long)pgno, (u_long)meta->re_len));
ret = DB_VERIFY_FATAL;
goto err;
} else {
@@ -80,7 +83,8 @@ __qam_vrfy_meta(dbp, vdp, meta, pgno, flags)
vdp->rec_page = meta->rec_page;
}
-err: if ((t_ret = __db_vrfy_putpageinfo(vdp, pip)) != 0 && ret == 0)
+err: if ((t_ret =
+ __db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0 && ret == 0)
ret = t_ret;
return (ret == 0 && isbad == 1 ? DB_VERIFY_BAD : ret);
}
@@ -114,14 +118,15 @@ __qam_vrfy_data(dbp, vdp, h, pgno, flags)
* some gross games to fake it out.
*/
fakedb.q_internal = &fakeq;
+ fakedb.flags = dbp->flags;
fakeq.re_len = vdp->re_len;
for (i = 0; i < vdp->rec_page; i++) {
qp = QAM_GET_RECORD(&fakedb, h, i);
if ((u_int8_t *)qp >= (u_int8_t *)h + dbp->pgsize) {
EPRINT((dbp->dbenv,
- "Queue record %lu extends past end of page %lu",
- i, pgno));
+ "Page %lu: queue record %lu extends past end of page",
+ (u_long)pgno, (u_long)i));
return (DB_VERIFY_BAD);
}
@@ -129,8 +134,8 @@ __qam_vrfy_data(dbp, vdp, h, pgno, flags)
qflags &= !(QAM_VALID | QAM_SET);
if (qflags != 0) {
EPRINT((dbp->dbenv,
- "Queue record %lu on page %lu has bad flags",
- i, pgno));
+ "Page %lu: queue record %lu has bad flags",
+ (u_long)pgno, (u_long)i));
return (DB_VERIFY_BAD);
}
}
@@ -161,7 +166,8 @@ __qam_vrfy_structure(dbp, vdp, flags)
if (pip->type != P_QAMMETA) {
EPRINT((dbp->dbenv,
- "Queue database has no meta page"));
+ "Page %lu: queue database has no meta page",
+ (u_long)PGNO_BASE_MD));
isbad = 1;
goto err;
}
@@ -174,21 +180,21 @@ __qam_vrfy_structure(dbp, vdp, flags)
if (!LF_ISSET(DB_SALVAGE))
__db_vrfy_struct_feedback(dbp, vdp);
- if ((ret = __db_vrfy_putpageinfo(vdp, pip)) != 0 ||
+ if ((ret = __db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0 ||
(ret = __db_vrfy_getpageinfo(vdp, i, &pip)) != 0)
return (ret);
if (!F_ISSET(pip, VRFY_IS_ALLZEROES) &&
pip->type != P_QAMDATA) {
EPRINT((dbp->dbenv,
- "Queue database page %lu of incorrect type %lu",
- i, pip->type));
+ "Page %lu: queue database page of incorrect type %lu",
+ (u_long)i, (u_long)pip->type));
isbad = 1;
goto err;
} else if ((ret = __db_vrfy_pgset_inc(vdp->pgset, i)) != 0)
goto err;
}
-err: if ((ret = __db_vrfy_putpageinfo(vdp, pip)) != 0)
+err: if ((ret = __db_vrfy_putpageinfo(dbp->dbenv, vdp, pip)) != 0)
return (ret);
return (isbad == 1 ? DB_VERIFY_BAD : 0);
}