2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 2005, 2012 Oracle and/or its affiliates. All rights reserved.
10 static int b_recover_usage(void);
13 b_recover(int argc, char *argv[])
16 extern int optind, __db_getopt_reset;
25 * Recover was too slow before release 4.0 that it's not worth
28 #if DB_VERSION_MAJOR < 4
33 __db_getopt_reset = 1;
34 while ((ch = getopt(argc, argv, "C:c:")) != EOF)
37 cachesize = (u_int32_t)atoi(optarg);
44 return (b_recover_usage());
49 return (b_recover_usage());
51 /* Create the environment. */
52 DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
53 dbenv->set_errfile(dbenv, stderr);
54 DB_BENCH_ASSERT(dbenv->set_cachesize(dbenv, 0, cachesize, 0) == 0);
57 (DB_CREATE | DB_INIT_LOCK | \
58 DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE)
59 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
60 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, NULL, OFLAGS, 0666) == 0);
62 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
63 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, OFLAGS, 0666) == 0);
65 #if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 1
66 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, OFLAGS, 0666) == 0);
69 /* Create the database. */
70 DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
71 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
72 DB_BENCH_ASSERT(dbp->open(dbp, NULL,
73 TESTFILE, NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0666) == 0);
76 dbp->open(dbp, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
79 /* Initialize the data. */
80 memset(&key, 0, sizeof(key));
81 memset(&data, 0, sizeof(data));
82 key.size = data.size = 20;
83 key.data = data.data = "01234567890123456789";
85 /* Start/commit a transaction count times. */
86 for (i = 0; i < count; ++i) {
87 #if DB_VERSION_MAJOR < 4
89 txn_begin(dbenv, NULL, &txn, DB_TXN_NOSYNC) == 0);
90 DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
91 DB_BENCH_ASSERT(txn_commit(txn, 0) == 0);
94 dbenv->txn_begin(dbenv, NULL, &txn, DB_TXN_NOSYNC) == 0);
95 DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
96 DB_BENCH_ASSERT(txn->commit(txn, 0) == 0);
100 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
101 DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
103 /* Create a new DB_ENV handle. */
104 DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
105 dbenv->set_errfile(dbenv, stderr);
107 dbenv->set_cachesize(dbenv, 0, 1048576 /* 1MB */, 0) == 0);
109 /* Now run recovery. */
111 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
112 DB_BENCH_ASSERT(dbenv->open(
113 dbenv, TESTDIR, NULL, OFLAGS | DB_RECOVER, 0666) == 0);
115 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
117 dbenv->open(dbenv, TESTDIR, OFLAGS | DB_RECOVER, 0666) == 0);
119 #if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 1
121 dbenv->open(dbenv, TESTDIR, OFLAGS | DB_RECOVER, 0666) == 0);
126 * We divide the time by the number of transactions, so an "operation"
127 * is the recovery of a single transaction.
129 printf("# recovery after %d transactions\n", count);
130 TIMER_DISPLAY(count);
132 DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
140 (void)fprintf(stderr, "usage: b_recover [-C cachesz] [-c count]\n");
141 return (EXIT_FAILURE);