Debian Codegraph @

build_vxworks/test/micro/b_load.c

raw
1 /*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
7 */
8 #include "bench.h"
9
10 static int b_load_usage(void);
11
12 int
13 b_load(int argc, char *argv[])
14 {
15 extern char *optarg;
16 extern int optind, __db_getopt_reset;
17 DB *dbp;
18 DBTYPE type;
19 DBT key, data;
20 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
21 DB_HEAP_RID rid;
22 #endif
23 db_recno_t recno;
24 u_int32_t cachesize;
25 int ch, i, count, duplicate;
26 char *ts, buf[32];
27
28 type = DB_BTREE;
29 cachesize = MEGABYTE;
30 count = 100000;
31 duplicate = 0;
32 ts = "Btree";
33 __db_getopt_reset = 1;
34 while ((ch = getopt(argc, argv, "C:c:dt:")) != EOF)
35 switch (ch) {
36 case 'C':
37 cachesize = (u_int32_t)atoi(optarg);
38 break;
39 case 'c':
40 count = atoi(optarg);
41 break;
42 case 'd':
43 duplicate = 1;
44 break;
45 case 't':
46 switch (optarg[0]) {
47 case 'B': case 'b':
48 ts = "Btree";
49 type = DB_BTREE;
50 break;
51 case 'H': case 'h':
52 if (optarg[1] == 'E' || optarg[1] == 'e') {
53 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
54 if (b_util_have_heap())
55 return (0);
56 ts = "Heap";
57 type = DB_HEAP;
58 #else
59 fprintf(stderr,
60 "b_curwalk: Heap is not supported! \n");
61 return (EXIT_SUCCESS);
62 #endif
63 } else {
64 if (b_util_have_hash())
65 return (0);
66 ts = "Hash";
67 type = DB_HASH;
68 }
69 break;
70 case 'Q': case 'q':
71 if (b_util_have_queue())
72 return (0);
73 ts = "Queue";
74 type = DB_QUEUE;
75 break;
76 case 'R': case 'r':
77 ts = "Recno";
78 type = DB_RECNO;
79 break;
80 default:
81 return (b_load_usage());
82 }
83 break;
84 case '?':
85 default:
86 return (b_load_usage());
87 }
88 argc -= optind;
89 argv += optind;
90 if (argc != 0)
91 return (b_load_usage());
92
93 /* Usage. */
94 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
95 if (duplicate &&
96 (type == DB_QUEUE || type == DB_RECNO || type == DB_HEAP)) {
97 fprintf(stderr,
98 "b_load: Queue, Recno and Heap don't support duplicates\n");
99 return (b_load_usage());
100 }
101 #else
102 if (duplicate && (type == DB_QUEUE || type == DB_RECNO)) {
103 fprintf(stderr,
104 "b_load: Queue an Recno don't support duplicates\n");
105 return (b_load_usage());
106 }
107 #endif
108
109 #if DB_VERSION_MAJOR < 3 || DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR < 1
110 /*
111 * DB versions prior to 3.1.17 didn't have off-page duplicates, so
112 * this test can run forever.
113 */
114 if (duplicate)
115 return (0);
116 #endif
117
118 /* Create the database. */
119 DB_BENCH_ASSERT(db_create(&dbp, NULL, 0) == 0);
120 DB_BENCH_ASSERT(dbp->set_cachesize(dbp, 0, cachesize, 0) == 0);
121 if (duplicate)
122 DB_BENCH_ASSERT(dbp->set_flags(dbp, DB_DUP) == 0);
123 dbp->set_errfile(dbp, stderr);
124
125 /* Set record length for Queue. */
126 if (type == DB_QUEUE)
127 DB_BENCH_ASSERT(dbp->set_re_len(dbp, 20) == 0);
128
129 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
130 DB_BENCH_ASSERT(
131 dbp->open(dbp, NULL, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
132 #else
133 DB_BENCH_ASSERT(
134 dbp->open(dbp, TESTFILE, NULL, type, DB_CREATE, 0666) == 0);
135 #endif
136
137 /* Initialize the data. */
138 memset(&key, 0, sizeof(key));
139 memset(&data, 0, sizeof(data));
140
141 /* Insert count in-order key/data pairs. */
142 TIMER_START;
143 if (duplicate) {
144 key.size = 10;
145 key.data = "01234567890123456789";
146 data.data = buf;
147 data.size = 20;
148 for (i = 0; i < count; ++i) {
149 (void)snprintf(buf, sizeof(buf), "%020d", i);
150 DB_BENCH_ASSERT(
151 dbp->put(dbp, NULL, &key, &data, 0) == 0);
152 }
153 } else {
154 data.data = buf;
155 data.size = 20;
156 if (type == DB_BTREE || type == DB_HASH) {
157 key.size = 10;
158 key.data = buf;
159 for (i = 0; i < count; ++i) {
160 (void)snprintf(buf, sizeof(buf), "%010d", i);
161 DB_BENCH_ASSERT(
162 dbp->put(dbp, NULL, &key, &data, 0) == 0);
163 }
164 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
165 } else if (type == DB_HEAP) {
166 key.data = &rid;
167 key.size = sizeof(rid);
168 for (i = 0; i < count; ++i)
169 DB_BENCH_ASSERT(dbp->put(dbp,
170 NULL, &key, &data, DB_APPEND) == 0);
171 #endif
172 } else {
173 key.data = &recno;
174 key.size = sizeof(recno);
175 for (i = 0, recno = 1; i < count; ++i, ++recno)
176 DB_BENCH_ASSERT(
177 dbp->put(dbp, NULL, &key, &data, 0) == 0);
178 }
179 }
180
181 TIMER_STOP;
182
183 printf("# %d %s database in-order put of 10/20 byte key/data %sitems\n",
184 count, ts, duplicate ? "duplicate " : "");
185 TIMER_DISPLAY(count);
186
187 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
188
189 return (0);
190 }
191
192 static int
193 b_load_usage()
194 {
195 (void)fprintf(stderr,
196 "usage: b_load [-d] [-C cachesz] [-c count] [-t type]\n");
197 return (EXIT_FAILURE);
198 }