39
39
#define MAX_RUN 5
40
40
#define MAX_TIERED_FILES 10
41
41
#define NUM_RECORDS 500
42
+ #define MAX_VALUE_SIZE 200
42
43
43
44
/* Constants and variables declaration. */
44
45
static const char conn_config [] =
45
46
"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 ] = "" ;
48
49
49
50
static TEST_OPTS * opts , _opts ;
50
51
static bool read_data = true;
52
+ static bool flush ;
53
+
54
+ static WT_RAND_STATE rnd ;
51
55
/* Forward declarations. */
52
56
53
57
static double calculate_std_deviation (const double * );
54
58
static void compute_wt_file_size (const char * , const char * , uint64_t * );
55
59
static void compute_tiered_file_size (const char * , const char * , uint64_t * );
60
+ static void fill_random_data (void );
56
61
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 );
61
66
62
67
static double avg_wtime_arr [MAX_RUN ], avg_rtime_arr [MAX_RUN ], avg_wthroughput_arr [MAX_RUN ],
63
68
avg_rthroughput_arr [MAX_RUN ];
@@ -70,7 +75,6 @@ static uint64_t avg_filesize_array[MAX_RUN];
70
75
int
71
76
main (int argc , char * argv [])
72
77
{
73
- bool flush ;
74
78
int i ;
75
79
opts = & _opts ;
76
80
memset (opts , 0 , sizeof (* opts ));
@@ -93,22 +97,22 @@ main(int argc, char *argv[])
93
97
/*
94
98
* Run test with 100K file size. Row store case.
95
99
*/
96
- run_test_clean ("100KB" , NUM_RECORDS , flush );
100
+ run_test_clean ("100KB" , NUM_RECORDS );
97
101
98
102
/*
99
103
* Run test with 1Mb file size. Row store case.
100
104
*/
101
- run_test_clean ("1MB" , NUM_RECORDS * 10 , flush );
105
+ run_test_clean ("1MB" , NUM_RECORDS * 10 );
102
106
103
107
/*
104
108
* Run test with 10 Mb file size. Row store case.
105
109
*/
106
- run_test_clean ("10MB" , NUM_RECORDS * 100 , flush );
110
+ run_test_clean ("10MB" , NUM_RECORDS * 100 );
107
111
108
112
/*
109
113
* Run test with 100 Mb file size. Row store case.
110
114
*/
111
- run_test_clean ("100MB" , NUM_RECORDS * 1000 , flush );
115
+ run_test_clean ("100MB" , NUM_RECORDS * 1000 );
112
116
flush = true;
113
117
}
114
118
@@ -143,20 +147,20 @@ difftime_sec(struct timeval t0, struct timeval t1)
143
147
* This function runs the test for configured number of times to compute the average time taken.
144
148
*/
145
149
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 )
147
151
{
148
152
char home_full [HOME_BUF_SIZE ];
149
153
double avg_wtime , avg_rtime , avg_wthroughput , avg_rthroughput ;
150
154
uint64_t avg_file_size ;
151
- int counter ;
155
+ uint32_t counter ;
152
156
153
157
avg_file_size = 0 ;
154
158
avg_wtime = avg_rtime = avg_rthroughput = avg_wthroughput = 0 ;
155
159
156
160
for (counter = 0 ; counter < MAX_RUN ; ++ counter ) {
157
161
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 );
160
164
}
161
165
162
166
/* Cleanup */
@@ -184,62 +188,79 @@ run_test_clean(const char *suffix, uint32_t num_records, bool flush)
184
188
calculate_std_deviation (avg_rthroughput_arr ));
185
189
}
186
190
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
+
187
207
/*
188
208
* recover_validate --
189
209
* Open wiredtiger and validate the data.
190
210
*/
191
211
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 )
193
213
{
194
214
struct timeval start , end ;
195
215
196
216
char buf [1024 ], rm_cmd [512 ];
197
- char * str_val ;
198
217
double diff_sec ;
199
218
int status ;
200
219
size_t val_1_size , val_2_size ;
201
- uint64_t i , str_len ;
220
+ uint64_t key , i , v ;
202
221
203
222
WT_CONNECTION * conn ;
204
223
WT_CURSOR * cursor ;
224
+ WT_ITEM item ;
205
225
WT_SESSION * session ;
206
226
207
227
/* Copy the data to a separate folder for debugging purpose. */
208
228
testutil_copy_data (home );
209
229
230
+ key = 0 ;
210
231
buf [0 ] = '\0' ;
211
232
/*
212
233
* Open the connection which forces recovery to be run.
213
234
*/
214
235
testutil_wiredtiger_open (opts , home , buf , NULL , & conn , true, true);
215
236
testutil_check (conn -> open_session (conn , NULL , NULL , & session ));
216
237
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 );
224
241
225
242
testutil_check (__wt_snprintf (rm_cmd , sizeof (rm_cmd ), "rm -rf %s/cache-bucket/*" , home ));
226
243
status = system (rm_cmd );
227
244
if (status < 0 )
228
245
testutil_die (status , "system: %s" , rm_cmd );
229
246
230
247
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 ;
232
249
233
250
gettimeofday (& start , 0 );
234
251
235
252
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 ;
240
260
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 );
242
262
}
263
+ testutil_assert (cursor -> next (cursor ) == WT_NOTFOUND );
243
264
gettimeofday (& end , 0 );
244
265
245
266
testutil_check (session -> close (session , NULL ));
@@ -256,7 +277,7 @@ recover_validate(const char *home, uint32_t num_records, uint64_t file_size, int
256
277
* parameter.
257
278
*/
258
279
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 )
260
281
{
261
282
struct timeval start , end ;
262
283
@@ -277,13 +298,13 @@ run_test(const char *home, uint32_t num_records, bool flush, int counter)
277
298
testutil_check (conn -> open_session (conn , NULL , NULL , & session ));
278
299
279
300
/* 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 ));
281
302
282
303
testutil_check (__wt_snprintf (buf , sizeof (buf ), flush ? "flush_tier=(enabled,force=true)" : "" ));
283
304
284
305
gettimeofday (& start , 0 );
285
306
286
- populate (session , num_records );
307
+ populate (session , num_records , counter );
287
308
testutil_check (session -> checkpoint (session , buf ));
288
309
289
310
gettimeofday (& end , 0 );
@@ -311,23 +332,23 @@ run_test(const char *home, uint32_t num_records, bool flush, int counter)
311
332
* Populate the table.
312
333
*/
313
334
static void
314
- populate (WT_SESSION * session , uint32_t num_records )
335
+ populate (WT_SESSION * session , uint32_t num_records , uint32_t counter )
315
336
{
316
337
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 ;
324
340
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 );
326
344
327
345
testutil_check (session -> open_cursor (session , opts -> uri , NULL , NULL , & cursor ));
328
346
for (i = 0 ; i < num_records ; i ++ ) {
347
+ fill_random_data ();
329
348
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 );
331
352
testutil_check (cursor -> insert (cursor ));
332
353
}
333
354
0 commit comments