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_put_usage(void);
11 static int b_put_secondary(DB *, const DBT *, const DBT *, DBT *);
14 b_put(int argc, char *argv[])
17 extern int optind, __db_getopt_reset;
22 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
26 u_int32_t cachesize, dsize;
27 int ch, i, count, secondaries;
37 __db_getopt_reset = 1;
38 while ((ch = getopt(argc, argv, "C:c:d:s:t:")) != EOF)
41 cachesize = (u_int32_t)atoi(optarg);
47 dsize = (u_int32_t)atoi(optarg);
50 secondaries = atoi(optarg);
59 if (optarg[1] == 'E' || optarg[1] == 'e') {
60 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
61 if (b_util_have_heap())
67 "b_curwalk: Heap is not supported! \n");
68 return (EXIT_SUCCESS);
71 if (b_util_have_hash())
78 if (b_util_have_queue())
88 return (b_put_usage());
93 return (b_put_usage());
98 return (b_put_usage());
100 #if DB_VERSION_MAJOR < 3 || DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 3
102 * Secondaries were added after DB 3.2.9.
108 /* Create the environment. */
109 DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
110 dbenv->set_errfile(dbenv, stderr);
111 DB_BENCH_ASSERT(dbenv->set_cachesize(dbenv, 0, cachesize, 0) == 0);
112 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 1
113 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
114 NULL, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0);
116 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
117 DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0);
121 * Create the database.
122 * Optionally set the record length for Queue.
124 DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
125 if (type == DB_QUEUE)
126 DB_BENCH_ASSERT(dbp->set_re_len(dbp, dsize) == 0);
127 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
129 dbp->open(dbp, NULL, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
132 dbp->open(dbp, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
135 /* Optionally create the secondaries. */
136 if (secondaries != 0) {
137 DB_BENCH_ASSERT((second =
138 calloc(sizeof(DB *), (size_t)secondaries)) != NULL);
139 for (i = 0; i < secondaries; ++i) {
140 DB_BENCH_ASSERT(db_create(&second[i], dbenv, 0) == 0);
141 (void)snprintf(buf, sizeof(buf), "%d.db", i);
142 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
143 DB_BENCH_ASSERT(second[i]->open(second[i], NULL,
144 buf, NULL, DB_BTREE, DB_CREATE, 0600) == 0);
146 DB_BENCH_ASSERT(second[i]->open(second[i],
147 buf, NULL, DB_BTREE, DB_CREATE, 0600) == 0);
149 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
151 * The DB_TXN argument to Db.associate was added in
154 DB_BENCH_ASSERT(dbp->associate(
155 dbp, NULL, second[i], b_put_secondary, 0) == 0);
157 DB_BENCH_ASSERT(dbp->associate(
158 dbp, second[i], b_put_secondary, 0) == 0);
163 /* Store a key/data pair. */
164 memset(&key, 0, sizeof(key));
165 memset(&data, 0, sizeof(data));
169 key.data = "01234567890123456789";
172 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
175 key.size = sizeof(rid);
182 key.size = sizeof(recno);
191 (data.data = malloc((size_t)dsize)) != NULL);
193 /* Store the key/data pair count times. */
195 for (i = 0; i < count; ++i) {
196 /* Change data value so the secondaries are updated. */
197 (void)snprintf(data.data, data.size, "%10lu", (u_long)i);
198 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
199 DB_BENCH_ASSERT(dbp->put(dbp,
200 NULL, &key, &data, type == DB_HEAP ? DB_APPEND : 0) == 0);
202 DB_BENCH_ASSERT(dbp->put(dbp, NULL, &key, &data, 0) == 0);
207 if (type == DB_BTREE || type == DB_HASH)
209 "# %d %s database put of 10 byte key, %lu byte data",
210 count, ts, (u_long)dsize);
212 printf("# %d %s database put of key, %lu byte data",
213 count, ts, (u_long)dsize);
215 printf(" with %d secondaries", secondaries);
217 TIMER_DISPLAY(count);
219 if (second != NULL) {
220 for (i = 0; i < secondaries; ++i)
221 DB_BENCH_ASSERT(second[i]->close(second[i], 0) == 0);
225 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
226 DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
232 b_put_secondary(dbp, pkey, pdata, skey)
234 const DBT *pkey, *pdata;
237 skey->data = pdata->data;
238 skey->size = pdata->size;
240 COMPQUIET(dbp, NULL);
241 COMPQUIET(pkey, NULL);
248 (void)fprintf(stderr, "usage: b_put %s\n",
249 "[-C cachesz] [-c count] [-d bytes] [-s secondaries] [-t type]");
250 return (EXIT_FAILURE);