1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
#include "bench.h"
static int usage(void);
int
b_recover(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
DB *dbp;
DBT key, data;
DB_ENV *dbenv;
DB_TXN *txn;
u_int32_t cachesize;
int ch, i, count;
/*
* Recover was too slow before release 4.0 that it's not worth
* running the test.
*/
#if DB_VERSION_MAJOR < 4
return (0);
#endif
cachesize = MEGABYTE;
count = 1000;
while ((ch = getopt(argc, argv, "C:c:")) != EOF)
switch (ch) {
case 'C':
cachesize = (u_int32_t)atoi(optarg);
break;
case 'c':
count = atoi(optarg);
break;
case '?':
default:
return (usage());
}
argc -= optind;
argv += optind;
if (argc != 0)
return (usage());
/* Create the environment. */
DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
dbenv->set_errfile(dbenv, stderr);
DB_BENCH_ASSERT(dbenv->set_cachesize(dbenv, 0, cachesize, 0) == 0);
#define OFLAGS \
(DB_CREATE | DB_INIT_LOCK | \
DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE)
#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, NULL, OFLAGS, 0666) == 0);
#endif
#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, OFLAGS, 0666) == 0);
#endif
#if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 1
DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, OFLAGS, 0666) == 0);
#endif
/* Create the database. */
DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
#if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
DB_BENCH_ASSERT(dbp->open(dbp, NULL,
TESTFILE, NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0666) == 0);
#else
DB_BENCH_ASSERT(
dbp->open(dbp, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
#endif
/* Initialize the data. */
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.size = data.size = 20;
key.data = data.data = "01234567890123456789";
/* Start/commit a transaction count times. */
for (i = 0; i < count; ++i) {
#if DB_VERSION_MAJOR < 4
DB_BENCH_ASSERT(
txn_begin(dbenv, NULL, &txn, DB_TXN_NOSYNC) == 0);
DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
DB_BENCH_ASSERT(txn_commit(txn, 0) == 0);
#else
DB_BENCH_ASSERT(
dbenv->txn_begin(dbenv, NULL, &txn, DB_TXN_NOSYNC) == 0);
DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
DB_BENCH_ASSERT(txn->commit(txn, 0) == 0);
#endif
}
DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
/* Create a new DB_ENV handle. */
DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
dbenv->set_errfile(dbenv, stderr);
DB_BENCH_ASSERT(
dbenv->set_cachesize(dbenv, 0, 1048576 /* 1MB */, 0) == 0);
/* Now run recovery. */
TIMER_START;
#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
DB_BENCH_ASSERT(dbenv->open(
dbenv, TESTDIR, NULL, OFLAGS | DB_RECOVER, 0666) == 0);
#endif
#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
DB_BENCH_ASSERT(
dbenv->open(dbenv, TESTDIR, OFLAGS | DB_RECOVER, 0666) == 0);
#endif
#if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 1
DB_BENCH_ASSERT(
dbenv->open(dbenv, TESTDIR, OFLAGS | DB_RECOVER, 0666) == 0);
#endif
TIMER_STOP;
/*
* We divide the time by the number of transactions, so an "operation"
* is the recovery of a single transaction.
*/
printf("# recovery after %d transactions\n", count);
TIMER_DISPLAY(count);
DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
return (0);
}
static int
usage()
{
(void)fprintf(stderr, "usage: b_recover [-C cachesz] [-c count]\n");
return (EXIT_FAILURE);
}
|