• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/build_vxworks/test_micro/
1/*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8#include "bench.h"
9
10static int b_txn_write_usage __P((void));
11
12#ifdef DB_INIT_REP
13static int b_txn_write_send __P((DB_ENV *,
14    const DBT *, const DBT *, const DB_LSN *, int, u_int32_t));
15
16/*
17 * b_txn_write_send --
18 *	A stubbed-out replication message function.
19 */
20static int
21b_txn_write_send(dbenv, control, rec, lsn, eid, flags)
22	DB_ENV *dbenv;
23	const DBT *control, *rec;
24	const DB_LSN *lsn;
25	int eid;
26	u_int32_t flags;
27{
28	COMPQUIET(dbenv, NULL);
29	COMPQUIET(control, NULL);
30	COMPQUIET(rec, NULL);
31	COMPQUIET(lsn, NULL);
32	COMPQUIET(eid, 0);
33	COMPQUIET(flags, 0);
34	return (0);
35}
36#endif
37
38int
39b_txn_write(int argc, char *argv[])
40{
41	extern char *optarg;
42	extern int optind, __db_getopt_reset;
43	DB *dbp;
44	DBT key, data;
45	DB_ENV *dbenv;
46	DB_TXN *txn;
47	u_int32_t flags, oflags;
48	int ch, i, count, rep_stub;
49	char *config;
50
51	count = 1000;
52	oflags = flags = 0;
53	rep_stub = 0;
54	config = "synchronous";
55	__db_getopt_reset = 1;
56	while ((ch = getopt(argc, argv, "ac:rw")) != EOF)
57		switch (ch) {
58		case 'a':
59			config = "nosync";
60			flags = DB_TXN_NOSYNC;
61			break;
62		case 'c':
63			count = atoi(optarg);
64			break;
65		case 'r':
66#ifdef DB_INIT_REP
67			rep_stub = 1;
68#else
69			exit(0);
70#endif
71			break;
72		case 'w':
73			config = "write-nosync";
74#ifdef DB_TXN_WRITE_NOSYNC
75			flags = DB_TXN_WRITE_NOSYNC;
76#else
77			exit(0);
78#endif
79			break;
80		case '?':
81		default:
82			return (b_txn_write_usage());
83		}
84	argc -= optind;
85	argv += optind;
86	if (argc != 0)
87		return (b_txn_write_usage());
88
89	/* Create the environment. */
90	DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
91	dbenv->set_errfile(dbenv, stderr);
92
93#ifdef DB_INIT_REP
94	if (rep_stub) {
95#if DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 5 || DB_VERSION_MAJOR > 4
96		DB_BENCH_ASSERT(
97		    dbenv->rep_set_transport(dbenv, 1, b_txn_write_send) == 0);
98#else
99		DB_BENCH_ASSERT(
100		    dbenv->set_rep_transport(dbenv, 1, b_txn_write_send) == 0);
101#endif
102		oflags |= DB_INIT_REP;
103	}
104#endif
105	oflags |= DB_CREATE | DB_INIT_LOCK |
106	    DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE;
107#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
108	DB_BENCH_ASSERT(
109	    dbenv->open(dbenv, TESTDIR, NULL, flags | oflags, 0666) == 0);
110#endif
111#if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 1
112	DB_BENCH_ASSERT(
113	    dbenv->open(dbenv, TESTDIR, flags | oflags, 0666) == 0);
114#endif
115#if DB_VERSION_MAJOR > 3 || DB_VERSION_MINOR > 1
116	if (flags != 0)
117		DB_BENCH_ASSERT(dbenv->set_flags(dbenv, flags, 1) == 0);
118	DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR, oflags, 0666) == 0);
119#endif
120
121#ifdef DB_INIT_REP
122	if (rep_stub)
123		DB_BENCH_ASSERT(
124		    dbenv->rep_start(dbenv, NULL, DB_REP_MASTER) == 0);
125#endif
126
127	/* Create the database. */
128	DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
129#if DB_VERSION_MAJOR >= 4 && DB_VERSION_MINOR >= 1
130	DB_BENCH_ASSERT(dbp->open(dbp, NULL,
131	    TESTFILE, NULL, DB_BTREE, DB_CREATE | DB_AUTO_COMMIT, 0666) == 0);
132#else
133	DB_BENCH_ASSERT(
134	    dbp->open(dbp, TESTFILE, NULL, DB_BTREE, DB_CREATE, 0666) == 0);
135#endif
136
137	/* Initialize the data. */
138	memset(&key, 0, sizeof(key));
139	memset(&data, 0, sizeof(data));
140	key.size = data.size = 20;
141	key.data = data.data = "01234567890123456789";
142
143	/* Start/commit a transaction count times. */
144	TIMER_START;
145	for (i = 0; i < count; ++i) {
146#if DB_VERSION_MAJOR < 4
147		DB_BENCH_ASSERT(txn_begin(dbenv, NULL, &txn, 0) == 0);
148		DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
149		DB_BENCH_ASSERT(txn_commit(txn, 0) == 0);
150#else
151		DB_BENCH_ASSERT(dbenv->txn_begin(dbenv, NULL, &txn, 0) == 0);
152		DB_BENCH_ASSERT(dbp->put(dbp, txn, &key, &data, 0) == 0);
153		DB_BENCH_ASSERT(txn->commit(txn, 0) == 0);
154#endif
155	}
156	TIMER_STOP;
157
158	printf("# %d %stransactions write %s commit pairs\n",
159	    count, rep_stub ? "replicated ": "", config);
160	TIMER_DISPLAY(count);
161
162	DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
163	DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
164
165	return (0);
166}
167
168static int
169b_txn_write_usage()
170{
171	(void)fprintf(stderr, "usage: b_txn_write [-arw] [-c count]\n");
172	return (EXIT_FAILURE);
173}
174