Skip to content

Commit 0ecf915

Browse files
lukechEvergreen Agent
authored andcommitted
Import wiredtiger: 2a414fdee92400156ab05de39b6f0c2363a73469 from branch mongodb-master
ref: 824e26b677..2a414fdee9 for: 6.3.0-rc0 WT-10294 Use WT API __wt_random instead of rand()
1 parent 8b31168 commit 0ecf915

File tree

5 files changed

+85
-46
lines changed

5 files changed

+85
-46
lines changed

src/third_party/wiredtiger/bench/tiered/push_pull.c

Lines changed: 65 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,30 @@
3939
#define MAX_RUN 5
4040
#define MAX_TIERED_FILES 10
4141
#define NUM_RECORDS 500
42+
#define MAX_VALUE_SIZE 200
4243

4344
/* Constants and variables declaration. */
4445
static const char conn_config[] =
4546
"create,cache_size=2GB,statistics=(all),statistics_log=(json,on_close,wait=1)";
46-
static const char table_config_row[] = "leaf_page_max=64KB,key_format=i,value_format=S";
47-
static char data_str[200] = "";
47+
static const char table_config[] = "leaf_page_max=64KB,key_format=i,value_format=u";
48+
static unsigned char data_str[MAX_VALUE_SIZE] = "";
4849

4950
static TEST_OPTS *opts, _opts;
5051
static bool read_data = true;
52+
static bool flush;
53+
54+
static WT_RAND_STATE rnd;
5155
/* Forward declarations. */
5256

5357
static double calculate_std_deviation(const double *);
5458
static void compute_wt_file_size(const char *, const char *, uint64_t *);
5559
static void compute_tiered_file_size(const char *, const char *, uint64_t *);
60+
static void fill_random_data(void);
5661
static void get_file_size(const char *, uint64_t *);
57-
static void recover_validate(const char *, uint32_t, uint64_t, int);
58-
static void run_test_clean(const char *, uint32_t, bool);
59-
static void run_test(const char *, uint32_t, bool, int);
60-
static void populate(WT_SESSION *, uint32_t);
62+
static void recover_validate(const char *, uint32_t, uint64_t, uint32_t);
63+
static void run_test_clean(const char *, uint32_t);
64+
static void run_test(const char *, uint32_t, uint32_t);
65+
static void populate(WT_SESSION *, uint32_t, uint32_t);
6166

6267
static double avg_wtime_arr[MAX_RUN], avg_rtime_arr[MAX_RUN], avg_wthroughput_arr[MAX_RUN],
6368
avg_rthroughput_arr[MAX_RUN];
@@ -70,7 +75,6 @@ static uint64_t avg_filesize_array[MAX_RUN];
7075
int
7176
main(int argc, char *argv[])
7277
{
73-
bool flush;
7478
int i;
7579
opts = &_opts;
7680
memset(opts, 0, sizeof(*opts));
@@ -93,22 +97,22 @@ main(int argc, char *argv[])
9397
/*
9498
* Run test with 100K file size. Row store case.
9599
*/
96-
run_test_clean("100KB", NUM_RECORDS, flush);
100+
run_test_clean("100KB", NUM_RECORDS);
97101

98102
/*
99103
* Run test with 1Mb file size. Row store case.
100104
*/
101-
run_test_clean("1MB", NUM_RECORDS * 10, flush);
105+
run_test_clean("1MB", NUM_RECORDS * 10);
102106

103107
/*
104108
* Run test with 10 Mb file size. Row store case.
105109
*/
106-
run_test_clean("10MB", NUM_RECORDS * 100, flush);
110+
run_test_clean("10MB", NUM_RECORDS * 100);
107111

108112
/*
109113
* Run test with 100 Mb file size. Row store case.
110114
*/
111-
run_test_clean("100MB", NUM_RECORDS * 1000, flush);
115+
run_test_clean("100MB", NUM_RECORDS * 1000);
112116
flush = true;
113117
}
114118

@@ -143,20 +147,20 @@ difftime_sec(struct timeval t0, struct timeval t1)
143147
* This function runs the test for configured number of times to compute the average time taken.
144148
*/
145149
static void
146-
run_test_clean(const char *suffix, uint32_t num_records, bool flush)
150+
run_test_clean(const char *suffix, uint32_t num_records)
147151
{
148152
char home_full[HOME_BUF_SIZE];
149153
double avg_wtime, avg_rtime, avg_wthroughput, avg_rthroughput;
150154
uint64_t avg_file_size;
151-
int counter;
155+
uint32_t counter;
152156

153157
avg_file_size = 0;
154158
avg_wtime = avg_rtime = avg_rthroughput = avg_wthroughput = 0;
155159

156160
for (counter = 0; counter < MAX_RUN; ++counter) {
157161
testutil_check(__wt_snprintf(
158-
home_full, HOME_BUF_SIZE, "%s_%s_%d_%d", opts->home, suffix, flush, counter));
159-
run_test(home_full, num_records, flush, counter);
162+
home_full, HOME_BUF_SIZE, "%s_%s_%d_%" PRIu32, opts->home, suffix, flush, counter));
163+
run_test(home_full, num_records, counter);
160164
}
161165

162166
/* Cleanup */
@@ -184,62 +188,79 @@ run_test_clean(const char *suffix, uint32_t num_records, bool flush)
184188
calculate_std_deviation(avg_rthroughput_arr));
185189
}
186190

191+
/*
192+
* fill_random_data --
193+
* Fill random data.
194+
*/
195+
static void
196+
fill_random_data(void)
197+
{
198+
uint64_t i, str_len;
199+
200+
str_len = sizeof(data_str) / sizeof(data_str[0]);
201+
for (i = 0; i < str_len - 1; i++)
202+
data_str[i] = '\x01' + (uint8_t)__wt_random(&rnd) % 255;
203+
204+
data_str[str_len - 1] = '\0';
205+
}
206+
187207
/*
188208
* recover_validate --
189209
* Open wiredtiger and validate the data.
190210
*/
191211
static void
192-
recover_validate(const char *home, uint32_t num_records, uint64_t file_size, int counter)
212+
recover_validate(const char *home, uint32_t num_records, uint64_t file_size, uint32_t counter)
193213
{
194214
struct timeval start, end;
195215

196216
char buf[1024], rm_cmd[512];
197-
char *str_val;
198217
double diff_sec;
199218
int status;
200219
size_t val_1_size, val_2_size;
201-
uint64_t i, str_len;
220+
uint64_t key, i, v;
202221

203222
WT_CONNECTION *conn;
204223
WT_CURSOR *cursor;
224+
WT_ITEM item;
205225
WT_SESSION *session;
206226

207227
/* Copy the data to a separate folder for debugging purpose. */
208228
testutil_copy_data(home);
209229

230+
key = 0;
210231
buf[0] = '\0';
211232
/*
212233
* Open the connection which forces recovery to be run.
213234
*/
214235
testutil_wiredtiger_open(opts, home, buf, NULL, &conn, true, true);
215236
testutil_check(conn->open_session(conn, NULL, NULL, &session));
216237

217-
// srand((unsigned long)getpid() + num_records);
218-
srand((uint32_t)getpid() + num_records);
219-
str_len = sizeof(data_str) / sizeof(data_str[0]);
220-
for (i = 0; i < str_len - 1; i++)
221-
data_str[i] = 'a' + (uint32_t)rand() % 26;
222-
223-
data_str[str_len - 1] = '\0';
238+
/* Seed the random number generator */
239+
v = (uint32_t)getpid() + num_records + (2 * counter);
240+
__wt_random_init_custom_seed(&rnd, v);
224241

225242
testutil_check(__wt_snprintf(rm_cmd, sizeof(rm_cmd), "rm -rf %s/cache-bucket/*", home));
226243
status = system(rm_cmd);
227244
if (status < 0)
228245
testutil_die(status, "system: %s", rm_cmd);
229246

230247
testutil_check(session->open_cursor(session, opts->uri, NULL, NULL, &cursor));
231-
val_1_size = strlen(data_str);
248+
val_1_size = MAX_VALUE_SIZE;
232249

233250
gettimeofday(&start, 0);
234251

235252
for (i = 0; i < num_records; i++) {
236-
cursor->set_key(cursor, i + 1);
237-
testutil_check(cursor->search(cursor));
238-
testutil_check(cursor->get_value(cursor, &str_val));
239-
val_2_size = strlen(str_val);
253+
fill_random_data();
254+
255+
testutil_check(cursor->next(cursor));
256+
testutil_check(cursor->get_key(cursor, &key));
257+
testutil_assert(key == i + 1);
258+
testutil_check(cursor->get_value(cursor, &item));
259+
val_2_size = item.size;
240260
testutil_assert(val_1_size == val_2_size);
241-
testutil_assert(memcmp(data_str, str_val, val_1_size) == 0);
261+
testutil_assert(memcmp(data_str, item.data, item.size) == 0);
242262
}
263+
testutil_assert(cursor->next(cursor) == WT_NOTFOUND);
243264
gettimeofday(&end, 0);
244265

245266
testutil_check(session->close(session, NULL));
@@ -256,7 +277,7 @@ recover_validate(const char *home, uint32_t num_records, uint64_t file_size, int
256277
* parameter.
257278
*/
258279
static void
259-
run_test(const char *home, uint32_t num_records, bool flush, int counter)
280+
run_test(const char *home, uint32_t num_records, uint32_t counter)
260281
{
261282
struct timeval start, end;
262283

@@ -277,13 +298,13 @@ run_test(const char *home, uint32_t num_records, bool flush, int counter)
277298
testutil_check(conn->open_session(conn, NULL, NULL, &session));
278299

279300
/* Create and populate table. Checkpoint the data after that. */
280-
testutil_check(session->create(session, opts->uri, table_config_row));
301+
testutil_check(session->create(session, opts->uri, table_config));
281302

282303
testutil_check(__wt_snprintf(buf, sizeof(buf), flush ? "flush_tier=(enabled,force=true)" : ""));
283304

284305
gettimeofday(&start, 0);
285306

286-
populate(session, num_records);
307+
populate(session, num_records, counter);
287308
testutil_check(session->checkpoint(session, buf));
288309

289310
gettimeofday(&end, 0);
@@ -311,23 +332,23 @@ run_test(const char *home, uint32_t num_records, bool flush, int counter)
311332
* Populate the table.
312333
*/
313334
static void
314-
populate(WT_SESSION *session, uint32_t num_records)
335+
populate(WT_SESSION *session, uint32_t num_records, uint32_t counter)
315336
{
316337
WT_CURSOR *cursor;
317-
uint64_t i, str_len;
318-
319-
srand((uint32_t)getpid() + num_records);
320-
321-
str_len = sizeof(data_str) / sizeof(data_str[0]);
322-
for (i = 0; i < str_len - 1; i++)
323-
data_str[i] = 'a' + (uint32_t)rand() % 26;
338+
WT_ITEM item;
339+
uint64_t v, i;
324340

325-
data_str[str_len - 1] = '\0';
341+
/* Seed the random number generator */
342+
v = (uint32_t)getpid() + num_records + (2 * counter);
343+
__wt_random_init_custom_seed(&rnd, v);
326344

327345
testutil_check(session->open_cursor(session, opts->uri, NULL, NULL, &cursor));
328346
for (i = 0; i < num_records; i++) {
347+
fill_random_data();
329348
cursor->set_key(cursor, i + 1);
330-
cursor->set_value(cursor, data_str);
349+
item.data = data_str;
350+
item.size = sizeof(data_str);
351+
cursor->set_value(cursor, &item);
331352
testutil_check(cursor->insert(cursor));
332353
}
333354

src/third_party/wiredtiger/dist/s_funcs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ trap 'rm -f $t' 0 1 2 3 13 15
66

77
# List of files to search.
88
l=`sed -e '/^[a-z]/!d' -e 's/[ ].*$//' -e 's,^,../,' filelist`
9-
l="$l `echo ../src/*/*_inline.h ../src/utilities/*.c ../bench/wtperf/*.c`"
9+
l="$l `echo ../src/*/*_inline.h ../src/utilities/*.c ../bench/wtperf/*.c ../bench/tiered/*.c`"
1010

1111
(
1212
# Copy out the functions we don't use, but it's OK.

src/third_party/wiredtiger/import.data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"vendor": "wiredtiger",
33
"github": "wiredtiger/wiredtiger.git",
44
"branch": "mongodb-master",
5-
"commit": "824e26b67715b4e0f4be20bd46c969b9c8748bf9"
5+
"commit": "2a414fdee92400156ab05de39b6f0c2363a73469"
66
}

src/third_party/wiredtiger/src/include/extern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1895,6 +1895,8 @@ extern void __wt_page_out(WT_SESSION_IMPL *session, WT_PAGE **pagep);
18951895
extern void __wt_print_huffman_code(void *huffman_arg, uint16_t symbol);
18961896
extern void __wt_random_init(WT_RAND_STATE volatile *rnd_state)
18971897
WT_GCC_FUNC_DECL_ATTRIBUTE((visibility("default")));
1898+
extern void __wt_random_init_custom_seed(WT_RAND_STATE volatile *rnd_state, uint64_t v)
1899+
WT_GCC_FUNC_DECL_ATTRIBUTE((visibility("default")));
18981900
extern void __wt_random_init_seed(WT_SESSION_IMPL *session, WT_RAND_STATE volatile *rnd_state)
18991901
WT_GCC_FUNC_DECL_ATTRIBUTE((visibility("default")));
19001902
extern void __wt_read_row_time_window(

src/third_party/wiredtiger/src/support/rand.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
* result in a stored value of zero, in which case they will be stuck on zero forever. Take a local
3939
* copy of the values to avoid that, and read/write in atomic, 8B chunks.
4040
*/
41+
#undef M_V
42+
#define M_V(r) r.v
4143
#undef M_W
4244
#define M_W(r) r.x.w
4345
#undef M_Z
@@ -57,6 +59,20 @@ __wt_random_init(WT_RAND_STATE volatile *rnd_state) WT_GCC_FUNC_ATTRIBUTE((visib
5759
*rnd_state = rnd;
5860
}
5961

62+
/*
63+
* __wt_random_init_custom_seed --
64+
* Initialize the state of a 32-bit pseudo-random number with custom seed.
65+
*/
66+
void
67+
__wt_random_init_custom_seed(WT_RAND_STATE volatile *rnd_state, uint64_t v)
68+
WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
69+
{
70+
WT_RAND_STATE rnd;
71+
72+
M_V(rnd) = v;
73+
*rnd_state = rnd;
74+
}
75+
6076
/*
6177
* __wt_random_init_seed --
6278
* Initialize the state of a 32-bit pseudo-random number.

0 commit comments

Comments
 (0)