summaryrefslogtreecommitdiff
path: root/bdb/db_printlog
diff options
context:
space:
mode:
authorram@mysql.r18.ru <>2002-10-30 15:57:05 +0400
committerram@mysql.r18.ru <>2002-10-30 15:57:05 +0400
commit5e09392faa62ea38baa4bd46de5e4183da538e79 (patch)
tree6881a3cca88bea0bb9eeffd5aae34be437152786 /bdb/db_printlog
parent1c0f1712ca4869b537ada297930ef01dcb039bb9 (diff)
downloadmariadb-git-5e09392faa62ea38baa4bd46de5e4183da538e79.tar.gz
BDB 4.1.24
Diffstat (limited to 'bdb/db_printlog')
-rw-r--r--bdb/db_printlog/README11
-rw-r--r--bdb/db_printlog/db_printlog.c280
-rw-r--r--bdb/db_printlog/dbname.awk8
-rw-r--r--bdb/db_printlog/logstat.awk36
-rw-r--r--bdb/db_printlog/status.awk28
5 files changed, 294 insertions, 69 deletions
diff --git a/bdb/db_printlog/README b/bdb/db_printlog/README
index 7d8da505e49..d59f4c77f55 100644
--- a/bdb/db_printlog/README
+++ b/bdb/db_printlog/README
@@ -1,4 +1,4 @@
-# $Id: README,v 10.5 1999/11/21 23:08:01 bostic Exp $
+# $Id: README,v 10.6 2002/06/20 14:52:54 bostic Exp $
Berkeley DB log dump utility. This utility dumps out a DB log in human
readable form, a record at a time, to assist in recovery and transaction
@@ -10,14 +10,23 @@ commit.awk Output transaction ID of committed transactions.
count.awk Print out the number of log records for transactions
that we encountered.
+dbname.awk Take a comma-separated list of database names and spit
+ out all the log records that affect those databases.
+
fileid.awk Take a comma-separated list of file numbers and spit out
all the log records that affect those file numbers.
+logstat.awk Display log record count/size statistics.
+
pgno.awk Take a comma-separated list of page numbers and spit
out all the log records that affect those page numbers.
range.awk Print out a range of the log.
+rectype.awk Print out a range of the log -- command line should
+ set RECTYPE to the a comma separated list of the
+ rectypes (or partial strings of rectypes) sought.
+
status.awk Read through db_printlog output and list the transactions
encountered, and whether they commited or aborted.
diff --git a/bdb/db_printlog/db_printlog.c b/bdb/db_printlog/db_printlog.c
index 8b9fb74a6a9..af6d00d593a 100644
--- a/bdb/db_printlog/db_printlog.c
+++ b/bdb/db_printlog/db_printlog.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
@@ -9,14 +9,15 @@
#ifndef lint
static const char copyright[] =
- "Copyright (c) 1996-2000\nSleepycat Software Inc. All rights reserved.\n";
+ "Copyright (c) 1996-2002\nSleepycat Software Inc. All rights reserved.\n";
static const char revid[] =
- "$Id: db_printlog.c,v 11.23 2001/01/18 18:36:58 bostic Exp $";
+ "$Id: db_printlog.c,v 11.52 2002/08/08 03:50:38 bostic Exp $";
#endif
#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -24,21 +25,20 @@ static const char revid[] =
#endif
#include "db_int.h"
-#include "db_page.h"
-#include "btree.h"
-#include "db_am.h"
-#include "hash.h"
-#include "log.h"
-#include "qam.h"
-#include "txn.h"
-
-int main __P((int, char *[]));
-void usage __P((void));
-void version_check __P((void));
-
-DB_ENV *dbenv;
-const char
- *progname = "db_printlog"; /* Program name. */
+#include "dbinc/db_page.h"
+#include "dbinc/btree.h"
+#include "dbinc/fop.h"
+#include "dbinc/hash.h"
+#include "dbinc/log.h"
+#include "dbinc/qam.h"
+#include "dbinc/rep.h"
+#include "dbinc/txn.h"
+
+int main __P((int, char *[]));
+int usage __P((void));
+int version_check __P((const char *));
+int print_app_record __P((DB_ENV *, DBT *, DB_LSN *, db_recops));
+int open_rep_db __P((DB_ENV *, DB **, DBC **));
int
main(argc, argv)
@@ -47,42 +47,63 @@ main(argc, argv)
{
extern char *optarg;
extern int optind;
- DBT data;
+ const char *progname = "db_printlog";
+ DB *dbp;
+ DBC *dbc;
+ DB_ENV *dbenv;
+ DB_LOGC *logc;
+ int (**dtab) __P((DB_ENV *, DBT *, DB_LSN *, db_recops, void *));
+ size_t dtabsize;
+ DBT data, keydbt;
DB_LSN key;
- int ch, e_close, exitval, nflag, ret;
- char *home;
+ int ch, e_close, exitval, nflag, rflag, ret, repflag;
+ char *home, *passwd;
- version_check();
+ if ((ret = version_check(progname)) != 0)
+ return (ret);
- e_close = exitval = 0;
- nflag = 0;
- home = NULL;
- while ((ch = getopt(argc, argv, "h:NV")) != EOF)
+ dbp = NULL;
+ dbc = NULL;
+ logc = NULL;
+ e_close = exitval = nflag = rflag = repflag = 0;
+ home = passwd = NULL;
+ dtabsize = 0;
+ dtab = NULL;
+ while ((ch = getopt(argc, argv, "h:NP:rRV")) != EOF)
switch (ch) {
case 'h':
home = optarg;
break;
case 'N':
nflag = 1;
- if ((ret = db_env_set_panicstate(0)) != 0) {
- fprintf(stderr,
- "%s: db_env_set_panicstate: %s\n",
- progname, db_strerror(ret));
- return (1);
+ break;
+ case 'P':
+ passwd = strdup(optarg);
+ memset(optarg, 0, strlen(optarg));
+ if (passwd == NULL) {
+ fprintf(stderr, "%s: strdup: %s\n",
+ progname, strerror(errno));
+ return (EXIT_FAILURE);
}
break;
+ case 'r':
+ rflag = 1;
+ break;
+ case 'R':
+ repflag = 1;
+ break;
case 'V':
printf("%s\n", db_version(NULL, NULL, NULL));
- exit(0);
+ return (EXIT_SUCCESS);
case '?':
default:
- usage();
+ return (usage());
}
argc -= optind;
argv += optind;
if (argc > 0)
- usage();
+ return (usage());
/* Handle possible interruptions. */
__db_util_siginit();
@@ -101,8 +122,29 @@ main(argc, argv)
dbenv->set_errfile(dbenv, stderr);
dbenv->set_errpfx(dbenv, progname);
- if (nflag && (ret = dbenv->set_mutexlocks(dbenv, 0)) != 0) {
- dbenv->err(dbenv, ret, "set_mutexlocks");
+ if (nflag) {
+ if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
+ dbenv->err(dbenv, ret, "set_flags: DB_NOLOCKING");
+ goto shutdown;
+ }
+ if ((ret = dbenv->set_flags(dbenv, DB_NOPANIC, 1)) != 0) {
+ dbenv->err(dbenv, ret, "set_flags: DB_NOPANIC");
+ goto shutdown;
+ }
+ }
+
+ if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
+ passwd, DB_ENCRYPT_AES)) != 0) {
+ dbenv->err(dbenv, ret, "set_passwd");
+ goto shutdown;
+ }
+
+ /*
+ * Set up an app-specific dispatch function so that we can gracefully
+ * handle app-specific log records.
+ */
+ if ((ret = dbenv->set_app_dispatch(dbenv, print_app_record)) != 0) {
+ dbenv->err(dbenv, ret, "app_dispatch");
goto shutdown;
}
@@ -110,8 +152,19 @@ main(argc, argv)
* An environment is required, but as all we're doing is reading log
* files, we create one if it doesn't already exist. If we create
* it, create it private so it automatically goes away when we're done.
+ * If we are reading the replication database, do not open the env
+ * with logging, because we don't want to log the opens.
*/
- if ((ret = dbenv->open(dbenv, home,
+ if (repflag) {
+ if ((ret = dbenv->open(dbenv, home,
+ DB_INIT_MPOOL | DB_USE_ENVIRON, 0)) != 0 &&
+ (ret = dbenv->open(dbenv, home,
+ DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_USE_ENVIRON, 0))
+ != 0) {
+ dbenv->err(dbenv, ret, "open");
+ goto shutdown;
+ }
+ } else if ((ret = dbenv->open(dbenv, home,
DB_JOINENV | DB_USE_ENVIRON, 0)) != 0 &&
(ret = dbenv->open(dbenv, home,
DB_CREATE | DB_INIT_LOG | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0) {
@@ -120,33 +173,48 @@ main(argc, argv)
}
/* Initialize print callbacks. */
- if ((ret = __bam_init_print(dbenv)) != 0 ||
- (ret = __crdel_init_print(dbenv)) != 0 ||
- (ret = __db_init_print(dbenv)) != 0 ||
- (ret = __qam_init_print(dbenv)) != 0 ||
- (ret = __ham_init_print(dbenv)) != 0 ||
- (ret = __log_init_print(dbenv)) != 0 ||
- (ret = __txn_init_print(dbenv)) != 0) {
+ if ((ret = __bam_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __dbreg_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __crdel_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __db_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __fop_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __qam_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __ham_init_print(dbenv, &dtab, &dtabsize)) != 0 ||
+ (ret = __txn_init_print(dbenv, &dtab, &dtabsize)) != 0) {
dbenv->err(dbenv, ret, "callback: initialization");
goto shutdown;
}
+ /* Allocate a log cursor. */
+ if (repflag) {
+ if ((ret = open_rep_db(dbenv, &dbp, &dbc)) != 0)
+ goto shutdown;
+ } else if ((ret = dbenv->log_cursor(dbenv, &logc, 0)) != 0) {
+ dbenv->err(dbenv, ret, "DB_ENV->log_cursor");
+ goto shutdown;
+ }
+
memset(&data, 0, sizeof(data));
+ memset(&keydbt, 0, sizeof(keydbt));
while (!__db_util_interrupted()) {
- if ((ret = log_get(dbenv, &key, &data, DB_NEXT)) != 0) {
+ if (repflag) {
+ ret = dbc->c_get(dbc,
+ &keydbt, &data, rflag ? DB_PREV : DB_NEXT);
+ if (ret == 0)
+ key = ((REP_CONTROL *)keydbt.data)->lsn;
+ } else
+ ret = logc->get(logc,
+ &key, &data, rflag ? DB_PREV : DB_NEXT);
+ if (ret != 0) {
if (ret == DB_NOTFOUND)
break;
- dbenv->err(dbenv, ret, "log_get");
+ dbenv->err(dbenv,
+ ret, repflag ? "DB_LOGC->get" : "DBC->get");
goto shutdown;
}
- /*
- * XXX
- * We use DB_TXN_ABORT as our op because that's the only op
- * that calls the underlying recovery function without any
- * consideration as to the contents of the transaction list.
- */
- ret = __db_dispatch(dbenv, &data, &key, DB_TXN_ABORT, NULL);
+ ret = __db_dispatch(dbenv,
+ dtab, dtabsize, &data, &key, DB_TXN_PRINT, NULL);
/*
* XXX
@@ -163,6 +231,22 @@ main(argc, argv)
if (0) {
shutdown: exitval = 1;
}
+ if (logc != NULL && (ret = logc->close(logc, 0)) != 0)
+ exitval = 1;
+
+ if (dbc != NULL && (ret = dbc->c_close(dbc)) != 0)
+ exitval = 1;
+
+ if (dbp != NULL && (ret = dbp->close(dbp, 0)) != 0)
+ exitval = 1;
+
+ /*
+ * The dtab is allocated by __db_add_recovery (called by *_init_print)
+ * using the library malloc function (__os_malloc). It thus needs to be
+ * freed using the corresponding free (__os_free).
+ */
+ if (dtab != NULL)
+ __os_free(dbenv, dtab);
if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
exitval = 1;
fprintf(stderr,
@@ -172,18 +256,20 @@ shutdown: exitval = 1;
/* Resend any caught signal. */
__db_util_sigresend();
- return (exitval);
+ return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
-void
+int
usage()
{
- fprintf(stderr, "usage: db_printlog [-NV] [-h home]\n");
- exit (1);
+ fprintf(stderr, "%s\n",
+ "usage: db_printlog [-NrV] [-h home] [-P password]");
+ return (EXIT_FAILURE);
}
-void
-version_check()
+int
+version_check(progname)
+ const char *progname;
{
int v_major, v_minor, v_patch;
@@ -195,6 +281,80 @@ version_check()
"%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
DB_VERSION_PATCH, v_major, v_minor, v_patch);
- exit (1);
+ return (EXIT_FAILURE);
+ }
+ return (0);
+}
+
+/* Print an unknown, application-specific log record as best we can. */
+int
+print_app_record(dbenv, dbt, lsnp, op)
+ DB_ENV *dbenv;
+ DBT *dbt;
+ DB_LSN *lsnp;
+ db_recops op;
+{
+ int ch;
+ u_int32_t i, rectype;
+
+ DB_ASSERT(op == DB_TXN_PRINT);
+ COMPQUIET(dbenv, NULL);
+
+ /*
+ * Fetch the rectype, which always must be at the beginning of the
+ * record (if dispatching is to work at all).
+ */
+ memcpy(&rectype, dbt->data, sizeof(rectype));
+
+ /*
+ * Applications may wish to customize the output here based on the
+ * rectype. We just print the entire log record in the generic
+ * mixed-hex-and-printable format we use for binary data.
+ */
+ printf("[%lu][%lu]application specific record: rec: %lu\n",
+ (u_long)lsnp->file, (u_long)lsnp->offset, (u_long)rectype);
+ printf("\tdata: ");
+ for (i = 0; i < dbt->size; i++) {
+ ch = ((u_int8_t *)dbt->data)[i];
+ printf(isprint(ch) || ch == 0x0a ? "%c" : "%#x ", ch);
}
+ printf("\n\n");
+
+ return (0);
+}
+
+int
+open_rep_db(dbenv, dbpp, dbcp)
+ DB_ENV *dbenv;
+ DB **dbpp;
+ DBC **dbcp;
+{
+ int ret;
+
+ DB *dbp;
+ *dbpp = NULL;
+ *dbcp = NULL;
+
+ if ((ret = db_create(dbpp, dbenv, 0)) != 0) {
+ dbenv->err(dbenv, ret, "db_create");
+ return (ret);
+ }
+
+ dbp = *dbpp;
+ if ((ret =
+ dbp->open(dbp, NULL, "__db.rep.db", NULL, DB_BTREE, 0, 0)) != 0) {
+ dbenv->err(dbenv, ret, "DB->open");
+ goto err;
+ }
+
+ if ((ret = dbp->cursor(dbp, NULL, dbcp, 0)) != 0) {
+ dbenv->err(dbenv, ret, "DB->cursor");
+ goto err;
+ }
+
+ return (0);
+
+err: if (*dbpp != NULL)
+ (void)(*dbpp)->close(*dbpp, 0);
+ return (ret);
}
diff --git a/bdb/db_printlog/dbname.awk b/bdb/db_printlog/dbname.awk
index d070335127c..47955994579 100644
--- a/bdb/db_printlog/dbname.awk
+++ b/bdb/db_printlog/dbname.awk
@@ -1,4 +1,4 @@
-# $Id: dbname.awk,v 1.2 2000/08/03 15:06:39 ubell Exp $
+# $Id: dbname.awk,v 1.5 2002/05/07 05:45:51 ubell Exp $
#
# Take a comma-separated list of database names and spit out all the
# log records that affect those databases.
@@ -16,7 +16,7 @@ NR == 1 {
myfile = -1;
}
-/^\[.*log_register/ {
+/^\[.*dbreg_register/ {
register = 1;
}
/opcode:/ {
@@ -58,8 +58,6 @@ NR == 1 {
}
}
-
-
/^\[/{
if (printme == 1) {
printf("%s\n", rec);
@@ -69,6 +67,8 @@ NR == 1 {
rec = $0
}
+
+TXN == 1 && /txn_regop/ {printme = 1}
/^ /{
rec = sprintf("%s\n%s", rec, $0);
}
diff --git a/bdb/db_printlog/logstat.awk b/bdb/db_printlog/logstat.awk
new file mode 100644
index 00000000000..1009343eba4
--- /dev/null
+++ b/bdb/db_printlog/logstat.awk
@@ -0,0 +1,36 @@
+# $Id: logstat.awk,v 1.1 2002/05/10 15:19:13 bostic Exp $
+#
+# Output accumulated log record count/size statistics.
+BEGIN {
+ l_file = 0;
+ l_offset = 0;
+}
+
+/^\[/{
+ gsub("[][: ]", " ", $1)
+ split($1, a)
+
+ if (a[1] == l_file) {
+ l[a[3]] += a[2] - l_offset
+ ++n[a[3]]
+ } else
+ ++s[a[3]]
+
+ l_file = a[1]
+ l_offset = a[2]
+}
+
+END {
+ # We can't figure out the size of the first record in each log file,
+ # use the average for other records we found as an estimate.
+ for (i in s)
+ if (s[i] != 0 && n[i] != 0) {
+ l[i] += s[i] * (l[i]/n[i])
+ n[i] += s[i]
+ delete s[i]
+ }
+ for (i in l)
+ printf "%s: %d (n: %d, avg: %.2f)\n", i, l[i], n[i], l[i]/n[i]
+ for (i in s)
+ printf "%s: unknown (n: %d, unknown)\n", i, s[i]
+}
diff --git a/bdb/db_printlog/status.awk b/bdb/db_printlog/status.awk
index 42e24b078b9..13df0b6194a 100644
--- a/bdb/db_printlog/status.awk
+++ b/bdb/db_printlog/status.awk
@@ -1,14 +1,17 @@
-# $Id: status.awk,v 10.2 1999/11/21 18:01:43 bostic Exp $
+# $Id: status.awk,v 10.3 2002/04/11 01:35:24 margo Exp $
#
# Read through db_printlog output and list all the transactions encountered
# and whether they commited or aborted.
#
# 1 = started
# 2 = commited
+# 3 = explicitly aborted
+# 4 = other
BEGIN {
cur_txn = 0
}
/^\[/{
+ in_regop = 0
if (status[$5] == 0) {
status[$5] = 1;
txns[cur_txn] = $5;
@@ -16,11 +19,28 @@ BEGIN {
}
}
/txn_regop/ {
- status[$5] = 2
+ txnid = $5
+ in_regop = 1
+}
+/opcode:/ {
+ if (in_regop == 1) {
+ if ($2 == 1)
+ status[txnid] = 2
+ else if ($2 == 3)
+ status[txnid] = 3
+ else
+ status[txnid] = 4
+ }
}
END {
for (i = 0; i < cur_txn; i++) {
- printf("%s\t%s\n",
- txns[i], status[txns[i]] == 1 ? "ABORT" : "COMMIT");
+ if (status[txns[i]] == 1)
+ printf("%s\tABORT\n", txns[i]);
+ if (status[txns[i]] == 2)
+ printf("%s\tCOMMIT\n", txns[i]);
+ if (status[txns[i]] == 3)
+ printf("%s\tABORT\n", txns[i]);
+ if (status[txns[i]] == 4)
+ printf("%s\tOTHER\n", txns[i]);
}
}