~drizzle-trunk/drizzle/development

381 by Monty Taylor
Reformatted slap and test.
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1719.2.3 by Vijay Samuel
Merge removed the drizzled/option.h include from client_priv.h and archive_reader.
4
 *  Copyright (C) 2010 Vijay Samuel
381 by Monty Taylor
Reformatted slap and test.
5
 *  Copyright (C) 2008 MySQL
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
1 by brian
clean slate
21
22
23
/*
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
24
  Drizzle Slap
1 by brian
clean slate
25
26
  A simple program designed to work as if multiple clients querying the database,
27
  then reporting the timing of each stage.
28
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
29
  Drizzle slap runs three stages:
1 by brian
clean slate
30
  1) Create schema,table, and optionally any SP or data you want to beign
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
31
  the test with. (single client)
1 by brian
clean slate
32
  2) Load test (many clients)
33
  3) Cleanup (disconnection, drop table if specified, single client)
34
35
  Examples:
36
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
37
  Supply your own create and query SQL statements, with 50 clients
1 by brian
clean slate
38
  querying (200 selects for each):
39
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
40
  drizzleslap --delimiter=";" \
41
  --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
42
  --query="SELECT * FROM A" --concurrency=50 --iterations=200
1 by brian
clean slate
43
44
  Let the program build the query SQL statement with a table of two int
45
  columns, three varchar columns, five clients querying (20 times each),
46
  don't create the table or insert the data (using the previous test's
47
  schema and data):
48
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
49
  drizzleslap --concurrency=5 --iterations=20 \
50
  --number-int-cols=2 --number-char-cols=3 \
51
  --auto-generate-sql
1 by brian
clean slate
52
53
  Tell the program to load the create, insert and query SQL statements from
54
  the specified files, where the create.sql file has multiple table creation
55
  statements delimited by ';' and multiple insert statements delimited by ';'.
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
56
  The --query file will have multiple queries delimited by ';', run all the
1 by brian
clean slate
57
  load statements, and then run all the queries in the query file
58
  with five clients (five times each):
59
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
60
  drizzleslap --concurrency=5 \
61
  --iterations=5 --query=query.sql --create=create.sql \
62
  --delimiter=";"
1 by brian
clean slate
63
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
64
  @todo
1 by brian
clean slate
65
  Add language for better tests
66
  String length for files and those put on the command line are not
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
67
  setup to handle binary data.
1 by brian
clean slate
68
  More stats
69
  Break up tests and run them on multiple hosts at once.
70
  Allow output to be fed into a database directly.
71
72
*/
73
1531.3.1 by Monty Taylor
Fixed the centos issue.
74
#include "config.h"
1 by brian
clean slate
75
76
#include "client_priv.h"
77
#include <signal.h>
78
#include <stdarg.h>
79
#include <sys/types.h>
80
#include <sys/wait.h>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
81
#ifdef HAVE_SYS_STAT_H
82
# include <sys/stat.h>
83
#endif
84
#include <fcntl.h>
85
#include <math.h>
86
#include <cassert>
87
#include <cstdlib>
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
88
#include <string>
1531.2.1 by Vijay Samuel
Slap refactored
89
#include <iostream>
1531.2.27 by Vijay Samuel
Slap completely refactored with boost::program_options.
90
#include <fstream>
1241.9.58 by Monty Taylor
Dear god. I think we're not including anything from mysys in drizzled anymore.
91
#include <pthread.h>
1531.2.27 by Vijay Samuel
Slap completely refactored with boost::program_options.
92
#include <drizzled/configmake.h>
673.5.13 by Andrew Hutchings
Apply -p means port changes to all client apps
93
/* Added this for string translation. */
94
#include <drizzled/gettext.h>
1531.3.1 by Monty Taylor
Fixed the centos issue.
95
#include <boost/program_options.hpp>
96
97
#define SLAP_VERSION "1.5"
98
99
#define HUGE_STRING_LENGTH 8196
100
#define RAND_STRING_SIZE 126
101
#define DEFAULT_BLOB_SIZE 1024
673.5.13 by Andrew Hutchings
Apply -p means port changes to all client apps
102
398.1.5 by Monty Taylor
Removed C++ includes and std namespace from global.h.
103
using namespace std;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
104
using namespace drizzled;
1531.3.1 by Monty Taylor
Fixed the centos issue.
105
namespace po= boost::program_options;
398.1.5 by Monty Taylor
Removed C++ includes and std namespace from global.h.
106
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
107
#ifdef HAVE_SMEM
1 by brian
clean slate
108
static char *shared_memory_base_name=0;
109
#endif
110
111
/* Global Thread counter */
893 by Brian Aker
First pass of stripping uint
112
uint32_t thread_counter;
1 by brian
clean slate
113
pthread_mutex_t counter_mutex;
114
pthread_cond_t count_threshhold;
893 by Brian Aker
First pass of stripping uint
115
uint32_t master_wakeup;
1 by brian
clean slate
116
pthread_mutex_t sleeper_mutex;
117
pthread_cond_t sleep_threshhold;
118
119
/* Global Thread timer */
163 by Brian Aker
Merge Monty's code.
120
static bool timer_alarm= false;
1 by brian
clean slate
121
pthread_mutex_t timer_alarm_mutex;
122
pthread_cond_t timer_alarm_threshold;
123
1707.1.11 by Brian Aker
Move primary_keys to being a vector.
124
std::vector < std::string > primary_keys;
1 by brian
clean slate
125
1531.2.5 by Vijay Samuel
Updated slap
126
static string host, 
127
  opt_password, 
128
  user,
129
  user_supplied_query,
130
  user_supplied_pre_statements,
131
  user_supplied_post_statements,
132
  default_engine,
133
  pre_system,
134
  post_system;
135
1531.2.10 by Vijay Samuel
Slap refactored with boost::program_options.
136
static vector<string> user_supplied_queries;
1531.2.18 by Vijay Samuel
Refactored command line options for slap using boost::program_options
137
static string opt_verbose;
1745.2.1 by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar.
138
std::string opt_protocol;
1531.2.5 by Vijay Samuel
Updated slap
139
string delimiter;
140
141
string create_schema_string;
142
1745.2.1 by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar.
143
static bool use_drizzle_protocol= false;
163 by Brian Aker
Merge Monty's code.
144
static bool opt_preserve= true;
1531.2.5 by Vijay Samuel
Updated slap
145
static bool opt_only_print;
146
static bool opt_burnin;
163 by Brian Aker
Merge Monty's code.
147
static bool opt_ignore_sql_errors= false;
1627.2.2 by Monty Taylor
Moved password parsing code into get_password.cc.
148
static bool opt_silent,
1531.2.5 by Vijay Samuel
Updated slap
149
  auto_generate_sql_autoincrement,
150
  auto_generate_sql_guid_primary,
151
  auto_generate_sql;
152
std::string opt_auto_generate_sql_type;
1 by brian
clean slate
153
1531.2.19 by Vijay Samuel
Refactored command line options for slap using boost::program_options
154
static int32_t verbose= 0;
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
155
static uint32_t delimiter_length;
893 by Brian Aker
First pass of stripping uint
156
static uint32_t commit_rate;
157
static uint32_t detach_rate;
158
static uint32_t opt_timer_length;
159
static uint32_t opt_delayed_start;
1531.2.8 by Vijay Samuel
Updated Slap
160
string num_blob_cols_opt,
161
  num_char_cols_opt,
162
  num_int_cols_opt;
1531.2.1 by Vijay Samuel
Slap refactored
163
string opt_label;
1 by brian
clean slate
164
static unsigned int opt_set_random_seed;
165
1531.2.2 by Vijay Samuel
Updated slap code
166
string auto_generate_selected_columns_opt;
1 by brian
clean slate
167
168
/* Yes, we do set defaults here */
1531.2.9 by Vijay Samuel
updated slap
169
static unsigned int num_int_cols= 1;
170
static unsigned int num_char_cols= 1;
171
static unsigned int num_blob_cols= 0;
1 by brian
clean slate
172
static unsigned int num_blob_cols_size;
173
static unsigned int num_blob_cols_size_min;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
174
static unsigned int num_int_cols_index= 0;
1 by brian
clean slate
175
static unsigned int num_char_cols_index= 0;
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
176
static uint32_t iterations;
151 by Brian Aker
Ulonglong to uint64_t
177
static uint64_t actual_queries= 0;
178
static uint64_t auto_actual_queries;
179
static uint64_t auto_generate_sql_unique_write_number;
180
static uint64_t auto_generate_sql_unique_query_number;
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
181
static uint32_t auto_generate_sql_secondary_indexes;
151 by Brian Aker
Ulonglong to uint64_t
182
static uint64_t num_of_query;
1531.3.1 by Monty Taylor
Fixed the centos issue.
183
static uint64_t auto_generate_sql_number;
1531.2.5 by Vijay Samuel
Updated slap
184
string concurrency_str;
185
string create_string;
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
186
std::vector <uint32_t> concurrency;
1 by brian
clean slate
187
673.5.13 by Andrew Hutchings
Apply -p means port changes to all client apps
188
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
1531.2.1 by Vijay Samuel
Slap refactored
189
std::string opt_csv_str;
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
190
int csv_file;
1 by brian
clean slate
191
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
192
static int process_options(void);
1531.2.9 by Vijay Samuel
updated slap
193
static uint32_t opt_drizzle_port= 0;
1 by brian
clean slate
194
195
196
/* Types */
1707.1.9 by Brian Aker
Partial pass through the string in statement.
197
enum slap_query_t {
1 by brian
clean slate
198
  SELECT_TYPE= 0,
199
  UPDATE_TYPE= 1,
200
  INSERT_TYPE= 2,
201
  UPDATE_TYPE_REQUIRES_PREFIX= 3,
202
  CREATE_TABLE_TYPE= 4,
203
  SELECT_TYPE_REQUIRES_PREFIX= 5,
204
  DELETE_TYPE_REQUIRES_PREFIX= 6
1707.1.9 by Brian Aker
Partial pass through the string in statement.
205
};
1 by brian
clean slate
206
1441.3.1 by Vijay Samuel
all required updations have been made
207
class Statement;
208
209
class Statement 
210
{
211
public:
212
  Statement(char *in_string,
213
            size_t in_length,
1707.1.9 by Brian Aker
Partial pass through the string in statement.
214
            slap_query_t in_type,
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
215
            Statement *in_next) :
1441.3.1 by Vijay Samuel
all required updations have been made
216
    string(in_string),
217
    length(in_length),
218
    type(in_type),
219
    next(in_next)
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
220
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
221
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
222
  Statement() :
1441.3.1 by Vijay Samuel
all required updations have been made
223
    string(NULL),
224
    length(0),
225
    type(),
226
    next(NULL)
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
227
  { }
228
229
  ~Statement()
230
  {
231
    if (string)
232
      free(string);
233
  }
1441.3.1 by Vijay Samuel
all required updations have been made
234
   
235
  char *getString() const
236
  {
237
    return string;
238
  }
239
240
  size_t getLength() const
241
  {
242
    return length;
243
  }
244
1707.1.9 by Brian Aker
Partial pass through the string in statement.
245
  slap_query_t getType() const
1441.3.1 by Vijay Samuel
all required updations have been made
246
  {
247
    return type;
248
  }
249
250
  Statement *getNext() const
251
  {
252
    return next;
253
  }
254
255
  void setString(char *in_string)
256
  {
257
    string= in_string;
258
  }
259
1707.1.9 by Brian Aker
Partial pass through the string in statement.
260
  void setString(size_t length_arg)
261
  {
262
    string= (char *)calloc(length_arg + 1, sizeof(char));
263
    length= length_arg;
264
  }
265
1441.3.1 by Vijay Samuel
all required updations have been made
266
  void setString(size_t in_length, char in_char)
267
  {
268
    string[in_length]= in_char;
269
  }
270
271
  void setLength(size_t in_length)
272
  {
273
    length= in_length;
274
  }
275
1707.1.9 by Brian Aker
Partial pass through the string in statement.
276
  void setType(slap_query_t in_type)
1441.3.1 by Vijay Samuel
all required updations have been made
277
  {
278
    type= in_type;
279
  }
280
281
  void setNext(Statement *in_next)
282
  {
283
    next= in_next;
284
  }
285
286
private:
1 by brian
clean slate
287
  char *string;
288
  size_t length;
1707.1.9 by Brian Aker
Partial pass through the string in statement.
289
  slap_query_t type;
1441.3.1 by Vijay Samuel
all required updations have been made
290
  Statement *next;
1 by brian
clean slate
291
};
292
1441.3.1 by Vijay Samuel
all required updations have been made
293
class OptionString;
294
295
class OptionString 
296
{
297
public:
298
  OptionString(char *in_string,
299
               size_t in_length,
300
               char *in_option,
301
               size_t in_option_length,
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
302
               OptionString *in_next) :
1441.3.1 by Vijay Samuel
all required updations have been made
303
    string(in_string),
304
    length(in_length),
305
    option(in_option),
306
    option_length(in_option_length),
307
    next(in_next)
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
308
  { }  
1441.3.1 by Vijay Samuel
all required updations have been made
309
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
310
  OptionString() :
1441.3.1 by Vijay Samuel
all required updations have been made
311
    string(NULL),
312
    length(0),
313
    option(NULL),
314
    option_length(0),
315
    next(NULL)
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
316
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
317
1707.1.16 by Brian Aker
Memory cleanup around threads.
318
  ~OptionString()
319
  {
320
    if (getString())
321
      free(getString());
322
    if (getOption())
323
      free(getOption());
324
  }
325
1441.3.1 by Vijay Samuel
all required updations have been made
326
  char *getString() const
327
  {
328
    return string;
329
  }
330
331
  size_t getLength() const
332
  {
333
    return length;
334
  }
335
336
  char *getOption() const
337
  {
338
  return option;
339
  }
340
341
  size_t getOptionLength() const
342
  {
343
    return option_length;
344
  }
345
346
  OptionString *getNext() const
347
  {
348
    return next;
349
  }
350
351
  void setString(char *in_string)
352
  {
353
    string= in_string;
1707.1.10 by Brian Aker
Further memory cleanup
354
    length= strlen(in_string);
1441.3.1 by Vijay Samuel
all required updations have been made
355
  }
356
357
  void setOption(char *in_option)
358
  {
1707.1.20 by Brian Aker
Remove someof the code around an option saving its option
359
    option= strdup(in_option);
360
    option_length= strlen(in_option);
1441.3.1 by Vijay Samuel
all required updations have been made
361
  }
362
363
  void setNext(OptionString *in_next)
364
  {
365
    next= in_next;
366
  }
367
  
368
private:
1 by brian
clean slate
369
  char *string;
370
  size_t length;
371
  char *option;
372
  size_t option_length;
1441.3.1 by Vijay Samuel
all required updations have been made
373
  OptionString *next;
1 by brian
clean slate
374
};
375
1441.3.1 by Vijay Samuel
all required updations have been made
376
class Stats;
377
378
class Stats 
379
{
380
public:
381
  Stats(long int in_timing,
382
        uint32_t in_users,
383
        uint32_t in_real_users,
384
        uint32_t in_rows,
385
        long int in_create_timing,
1707.1.16 by Brian Aker
Memory cleanup around threads.
386
        uint64_t in_create_count) :
1441.3.1 by Vijay Samuel
all required updations have been made
387
    timing(in_timing),
388
    users(in_users),
389
    real_users(in_real_users),
390
    rows(in_rows),
391
    create_timing(in_create_timing),
392
    create_count(in_create_count)
1707.1.16 by Brian Aker
Memory cleanup around threads.
393
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
394
1707.1.16 by Brian Aker
Memory cleanup around threads.
395
  Stats() :
1441.3.1 by Vijay Samuel
all required updations have been made
396
    timing(0),
397
    users(0),
398
    real_users(0),
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
399
    rows(0),
1441.3.1 by Vijay Samuel
all required updations have been made
400
    create_timing(0),
401
    create_count(0)
1707.1.16 by Brian Aker
Memory cleanup around threads.
402
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
403
404
  long int getTiming() const
405
  {
406
    return timing;
407
  }
408
409
  uint32_t getUsers() const
410
  {
411
    return users;
412
  }   
413
414
  uint32_t getRealUsers() const
415
  {
416
    return real_users;
417
  }
418
419
  uint64_t getRows() const
420
  {
421
    return rows;
422
  }
423
424
  long int getCreateTiming() const
425
  {
426
    return create_timing;
427
  }
428
429
  uint64_t getCreateCount() const
430
  {
431
    return create_count;
432
  }
433
434
  void setTiming(long int in_timing)
435
  {
436
  timing= in_timing;
437
  }
438
439
  void setUsers(uint32_t in_users)
440
  {
441
    users= in_users;
442
  }
443
444
  void setRealUsers(uint32_t in_real_users)
445
  {
446
    real_users= in_real_users;
447
  }
448
449
  void setRows(uint64_t in_rows)
450
  {
451
    rows= in_rows;
452
  }
453
   
454
  void setCreateTiming(long int in_create_timing)
455
  {
456
    create_timing= in_create_timing;
457
  }
458
459
  void setCreateCount(uint64_t in_create_count)
460
  {
461
  create_count= in_create_count;
462
  }
463
  
464
private:
1 by brian
clean slate
465
  long int timing;
893 by Brian Aker
First pass of stripping uint
466
  uint32_t users;
467
  uint32_t real_users;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
468
  uint64_t rows;
1 by brian
clean slate
469
  long int create_timing;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
470
  uint64_t create_count;
1 by brian
clean slate
471
};
472
1441.3.1 by Vijay Samuel
all required updations have been made
473
class ThreadContext;
474
475
class ThreadContext 
476
{
477
public:
478
  ThreadContext(Statement *in_stmt,
1707.1.16 by Brian Aker
Memory cleanup around threads.
479
                uint64_t in_limit) :
1441.3.1 by Vijay Samuel
all required updations have been made
480
    stmt(in_stmt),
481
    limit(in_limit)
1707.1.16 by Brian Aker
Memory cleanup around threads.
482
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
483
1707.1.16 by Brian Aker
Memory cleanup around threads.
484
  ThreadContext() :
1441.3.1 by Vijay Samuel
all required updations have been made
485
    stmt(),
486
    limit(0)
1707.1.16 by Brian Aker
Memory cleanup around threads.
487
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
488
489
  Statement *getStmt() const
490
  {
491
    return stmt;
492
  }
493
494
  uint64_t getLimit() const
495
  {
496
    return limit;
497
  }
498
499
  void setStmt(Statement *in_stmt)
500
  {
501
    stmt= in_stmt;
502
  }
503
504
  void setLimit(uint64_t in_limit)
505
  {
506
    limit= in_limit;
507
  }  
508
509
private:
510
  Statement *stmt;
151 by Brian Aker
Ulonglong to uint64_t
511
  uint64_t limit;
1 by brian
clean slate
512
};
513
1441.3.1 by Vijay Samuel
all required updations have been made
514
class Conclusions;
515
516
class Conclusions 
517
{
518
519
public:
520
  Conclusions(char *in_engine,
521
              long int in_avg_timing,
522
              long int in_max_timing,
523
              long int in_min_timing,
524
              uint32_t in_users,
525
              uint32_t in_real_users,
526
              uint64_t in_avg_rows,
527
              long int in_sum_of_time,
528
              long int in_std_dev,
529
              long int in_create_avg_timing,
530
              long int in_create_max_timing,
531
              long int in_create_min_timing,
532
              uint64_t in_create_count,
533
              uint64_t in_max_rows,
1707.1.16 by Brian Aker
Memory cleanup around threads.
534
              uint64_t in_min_rows) :
1441.3.1 by Vijay Samuel
all required updations have been made
535
    engine(in_engine),
536
    avg_timing(in_avg_timing),
537
    max_timing(in_max_timing),
538
    min_timing(in_min_timing),
539
    users(in_users),
540
    real_users(in_real_users),
541
    avg_rows(in_avg_rows),
542
    sum_of_time(in_sum_of_time),
543
    std_dev(in_std_dev),
544
    create_avg_timing(in_create_avg_timing),
545
    create_max_timing(in_create_max_timing),
546
    create_min_timing(in_create_min_timing),
547
    create_count(in_create_count),
548
    max_rows(in_max_rows),
549
    min_rows(in_min_rows)
1707.1.16 by Brian Aker
Memory cleanup around threads.
550
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
551
1707.1.16 by Brian Aker
Memory cleanup around threads.
552
  Conclusions() :
1441.3.1 by Vijay Samuel
all required updations have been made
553
    engine(NULL),
554
    avg_timing(0),
555
    max_timing(0),
556
    min_timing(0),
557
    users(0),
558
    real_users(0),
559
    avg_rows(0),
560
    sum_of_time(0),
561
    std_dev(0),
562
    create_avg_timing(0),
563
    create_max_timing(0),
564
    create_min_timing(0),
565
    create_count(0),
566
    max_rows(0),
567
    min_rows(0)
1707.1.16 by Brian Aker
Memory cleanup around threads.
568
  { }
1441.3.1 by Vijay Samuel
all required updations have been made
569
570
  char *getEngine() const
571
  {
572
    return engine;
573
  }
574
  
575
  long int getAvgTiming() const
576
  {
577
    return avg_timing;
578
  }
579
580
  long int getMaxTiming() const
581
  {
582
    return max_timing;
583
  }
584
585
  long int getMinTiming() const
586
  {
587
    return min_timing;
588
  }
589
590
  uint32_t getUsers() const
591
  {
592
    return users;
593
  }
594
595
  uint32_t getRealUsers() const
596
  {
597
    return real_users;
598
  }
599
600
  uint64_t getAvgRows() const
601
  {
602
    return avg_rows;
603
  }   
604
605
  long int getSumOfTime() const
606
  {
607
    return sum_of_time;
608
  }
609
610
  long int getStdDev() const
611
  {
612
    return std_dev;
613
  }
614
615
  long int getCreateAvgTiming() const
616
  {
617
    return create_avg_timing;
618
  }
619
620
  long int getCreateMaxTiming() const
621
  {
622
    return create_max_timing;
623
  }
624
625
  long int getCreateMinTiming() const
626
  {
627
    return create_min_timing;
628
  }
629
   
630
  uint64_t getCreateCount() const
631
  {
632
    return create_count;
633
  }
634
635
  uint64_t getMinRows() const
636
  {
637
    return min_rows;
638
  }
639
640
  uint64_t getMaxRows() const
641
  {
642
    return max_rows;
643
  }
644
645
  void setEngine(char *in_engine) 
646
  {
647
    engine= in_engine;
648
  }
649
  
650
  void setAvgTiming(long int in_avg_timing) 
651
  {
652
    avg_timing= in_avg_timing;
653
  }
654
655
  void setMaxTiming(long int in_max_timing) 
656
  {
657
    max_timing= in_max_timing;
658
  }
659
660
  void setMinTiming(long int in_min_timing) 
661
  {
662
    min_timing= in_min_timing;
663
  }
664
665
  void setUsers(uint32_t in_users) 
666
  {
667
    users= in_users;
668
  }
669
670
  void setRealUsers(uint32_t in_real_users) 
671
  {
672
    real_users= in_real_users;
673
  }
674
675
  void setAvgRows(uint64_t in_avg_rows) 
676
  {
677
    avg_rows= in_avg_rows;
678
  }   
679
680
  void setSumOfTime(long int in_sum_of_time) 
681
  {
682
    sum_of_time= in_sum_of_time;
683
  }
684
685
  void setStdDev(long int in_std_dev) 
686
  {
687
    std_dev= in_std_dev;
688
  }
689
690
  void setCreateAvgTiming(long int in_create_avg_timing) 
691
  {
692
    create_avg_timing= in_create_avg_timing;
693
  }
694
695
  void setCreateMaxTiming(long int in_create_max_timing) 
696
  {
697
    create_max_timing= in_create_max_timing;
698
  }
699
700
  void setCreateMinTiming(long int in_create_min_timing) 
701
  {
702
    create_min_timing= in_create_min_timing;
703
  }
704
   
705
  void setCreateCount(uint64_t in_create_count) 
706
  {
707
    create_count= in_create_count;
708
  }
709
710
  void setMinRows(uint64_t in_min_rows) 
711
  {
712
    min_rows= in_min_rows;
713
  }
714
715
  void setMaxRows(uint64_t in_max_rows) 
716
  {
717
    max_rows= in_max_rows;
718
  }
719
720
private:
1 by brian
clean slate
721
  char *engine;
722
  long int avg_timing;
723
  long int max_timing;
724
  long int min_timing;
893 by Brian Aker
First pass of stripping uint
725
  uint32_t users;
726
  uint32_t real_users;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
727
  uint64_t avg_rows;
1 by brian
clean slate
728
  long int sum_of_time;
729
  long int std_dev;
730
  /* These are just for create time stats */
731
  long int create_avg_timing;
732
  long int create_max_timing;
733
  long int create_min_timing;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
734
  uint64_t create_count;
1 by brian
clean slate
735
  /* The following are not used yet */
398.1.8 by Monty Taylor
Enabled -Wlong-long.
736
  uint64_t max_rows;
737
  uint64_t min_rows;
1 by brian
clean slate
738
};
739
1441.3.1 by Vijay Samuel
all required updations have been made
740
741
static OptionString *engine_options= NULL;
742
static OptionString *query_options= NULL;
743
static Statement *pre_statements= NULL;
744
static Statement *post_statements= NULL;
745
static Statement *create_statements= NULL;
746
1707.1.17 by Brian Aker
REmove malloc() for vector.
747
static std::vector <Statement *> query_statements;
1 by brian
clean slate
748
static unsigned int query_statements_count;
749
750
751
/* Prototypes */
1441.3.1 by Vijay Samuel
all required updations have been made
752
void print_conclusions(Conclusions *con);
753
void print_conclusions_csv(Conclusions *con);
754
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr);
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
755
uint32_t parse_comma(const char *string, std::vector <uint32_t> &range);
1441.3.1 by Vijay Samuel
all required updations have been made
756
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm);
757
uint32_t parse_option(const char *origin, OptionString **stmt, char delm);
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
758
static int drop_schema(drizzle_con_st *con, const char *db);
893 by Brian Aker
First pass of stripping uint
759
uint32_t get_random_string(char *buf, size_t size);
1441.3.1 by Vijay Samuel
all required updations have been made
760
static Statement *build_table_string(void);
761
static Statement *build_insert_string(void);
762
static Statement *build_update_string(void);
763
static Statement * build_select_string(bool key);
764
static int generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt);
765
static int create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
766
                         OptionString *engine_stmt, Stats *sptr);
767
static int run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur,
151 by Brian Aker
Ulonglong to uint64_t
768
                         uint64_t limit);
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
769
extern "C" pthread_handler_t run_task(void *p);
770
extern "C" pthread_handler_t timer_thread(void *p);
1441.3.1 by Vijay Samuel
all required updations have been made
771
void statement_cleanup(Statement *stmt);
772
void option_cleanup(OptionString *stmt);
773
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr);
774
static int run_statements(drizzle_con_st *con, Statement *stmt);
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
775
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
776
void slap_close(drizzle_con_st *con);
777
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
1441.3.1 by Vijay Samuel
all required updations have been made
778
void standard_deviation (Conclusions *con, Stats *sptr);
1 by brian
clean slate
779
780
static const char ALPHANUMERICS[]=
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
781
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
1 by brian
clean slate
782
783
#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
784
785
786
static long int timedif(struct timeval a, struct timeval b)
787
{
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
788
  register int us, s;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
789
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
790
  us = a.tv_usec - b.tv_usec;
791
  us /= 1000;
792
  s = a.tv_sec - b.tv_sec;
793
  s *= 1000;
794
  return s + us;
1 by brian
clean slate
795
}
796
1531.2.10 by Vijay Samuel
Slap refactored with boost::program_options.
797
static void combine_queries(vector<string> queries)
798
{
799
  user_supplied_query.erase();
800
  for (vector<string>::iterator it= queries.begin();
801
       it != queries.end();
802
       ++it)
803
  {
804
    user_supplied_query.append(*it);
805
    user_supplied_query.append(delimiter);
806
  }
807
}
1531.2.29 by Vijay Samuel
Slap completely refactored using boost::program_options.
808
/**
809
 * commandline_options is the set of all options that can only be called via the command line.
810
811
 * client_options is the set of all options that can be defined via both command line and via
812
 * the configuration file client.cnf
813
814
 * slap_options is the set of all drizzleslap specific options which behave in a manner 
815
 * similar to that of client_options. It's configuration file is drizzleslap.cnf
816
817
 * long_options is the union of commandline_options, slap_options and client_options.
818
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
819
 * There are two configuration files per set of options, one which is defined by the user
820
 * which is found at either $XDG_CONFIG_HOME/drizzle or ~/.config/drizzle directory and the other which 
821
 * is the system configuration file which is found in the SYSCONFDIR/drizzle directory.
1531.2.29 by Vijay Samuel
Slap completely refactored using boost::program_options.
822
823
 * The system configuration file is over ridden by the user's configuration file which
824
 * in turn is over ridden by the command line.
825
 */
1 by brian
clean slate
826
int main(int argc, char **argv)
827
{
1531.2.1 by Vijay Samuel
Slap refactored
828
  char *password= NULL;
1531.2.7 by Vijay Samuel
updated slap
829
  try
830
  {
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
831
    po::options_description commandline_options("Options used only in command line");
832
    commandline_options.add_options()
833
      ("help,?","Display this help and exit")
834
      ("info,i","Gives information and exit")
835
      ("burnin",po::value<bool>(&opt_burnin)->default_value(false)->zero_tokens(),
836
       "Run full test case in infinite loop")
837
      ("ignore-sql-errors", po::value<bool>(&opt_ignore_sql_errors)->default_value(false)->zero_tokens(),
838
       "Ignore SQL errors in query run")
839
      ("create-schema",po::value<string>(&create_schema_string)->default_value("drizzleslap"),
840
       "Schema to run tests in")
841
      ("create",po::value<string>(&create_string)->default_value(""),
842
       "File or string to use to create tables")
843
      ("detach",po::value<uint32_t>(&detach_rate)->default_value(0),
844
       "Detach (close and re open) connections after X number of requests")
845
      ("iterations,i",po::value<uint32_t>(&iterations)->default_value(1),
846
       "Number of times to run the tests")
847
      ("label",po::value<string>(&opt_label)->default_value(""),
848
       "Label to use for print and csv")
849
      ("number-blob-cols",po::value<string>(&num_blob_cols_opt)->default_value(""),
850
       "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ")
851
      ("number-char-cols,x",po::value<string>(&num_char_cols_opt)->default_value(""),
852
       "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.")
853
      ("number-int-cols,y",po::value<string>(&num_int_cols_opt)->default_value(""),
854
       "Number of INT columns to create in table if specifying --auto-generate-sql.")
855
      ("number-of-queries",
856
       po::value<uint64_t>(&num_of_query)->default_value(0),
857
       "Limit each client to this number of queries(this is not exact)") 
858
      ("only-print",po::value<bool>(&opt_only_print)->default_value(false)->zero_tokens(),
859
       "This causes drizzleslap to not connect to the database instead print out what it would have done instead")
860
      ("post-query", po::value<string>(&user_supplied_post_statements)->default_value(""),
861
       "Query to run or file containing query to execute after tests have completed.")
862
      ("post-system",po::value<string>(&post_system)->default_value(""),
863
       "system() string to execute after tests have completed")
864
      ("pre-query",
865
       po::value<string>(&user_supplied_pre_statements)->default_value(""),
866
       "Query to run or file containing query to execute before running tests.")
867
      ("pre-system",po::value<string>(&pre_system)->default_value(""),
868
       "system() string to execute before running tests.")
869
      ("query,q",po::value<vector<string> >(&user_supplied_queries)->composing()->notifier(&combine_queries),
870
       "Query to run or file containing query")
871
      ("verbose,v", po::value<string>(&opt_verbose)->default_value("v"), "Increase verbosity level by one.")
872
      ("version,V","Output version information and exit") 
873
      ;
874
875
    po::options_description slap_options("Options specific to drizzleslap");
876
    slap_options.add_options()
877
      ("auto-generate-sql-select-columns",
878
       po::value<string>(&auto_generate_selected_columns_opt)->default_value(""),
879
       "Provide a string to use for the select fields used in auto tests")
880
      ("auto-generate-sql,a",po::value<bool>(&auto_generate_sql)->default_value(false)->zero_tokens(),
881
       "Generate SQL where not supplied by file or command line")  
882
      ("auto-generate-sql-add-autoincrement",
883
       po::value<bool>(&auto_generate_sql_autoincrement)->default_value(false)->zero_tokens(),
884
       "Add an AUTO_INCREMENT column to auto-generated tables")
885
      ("auto-generate-sql-execute-number",
886
       po::value<uint64_t>(&auto_actual_queries)->default_value(0),
887
       "See this number and generate a set of queries to run")
888
      ("auto-generate-sql-guid-primary",
889
       po::value<bool>(&auto_generate_sql_guid_primary)->default_value(false)->zero_tokens(),
890
       "Add GUID based primary keys to auto-generated tables")
891
      ("auto-generate-sql-load-type",
892
       po::value<string>(&opt_auto_generate_sql_type)->default_value("mixed"),
893
       "Specify test load type: mixed, update, write, key or read; default is mixed")  
894
      ("auto-generate-sql-secondary-indexes",
895
       po::value<uint32_t>(&auto_generate_sql_secondary_indexes)->default_value(0),
896
       "Number of secondary indexes to add to auto-generated tables")
897
      ("auto-generated-sql-unique-query-number",
898
       po::value<uint64_t>(&auto_generate_sql_unique_query_number)->default_value(10),
899
       "Number of unique queries to generate for automatic tests")
900
      ("auto-generate-sql-unique-write-number",
901
       po::value<uint64_t>(&auto_generate_sql_unique_write_number)->default_value(10),
902
       "Number of unique queries to generate for auto-generate-sql-write-number")
903
      ("auto-generate-sql-write-number",
904
       po::value<uint64_t>(&auto_generate_sql_number)->default_value(100),
905
       "Number of row inserts to perform for each thread (default is 100).")
906
      ("commit",po::value<uint32_t>(&commit_rate)->default_value(0),
907
       "Commit records every X number of statements")
908
      ("concurrency,c",po::value<string>(&concurrency_str)->default_value(""),
909
       "Number of clients to simulate for query to run")
910
      ("csv",po::value<std::string>(&opt_csv_str)->default_value(""),
911
       "Generate CSV output to named file or to stdout if no file is name.")
912
      ("delayed-start",po::value<uint32_t>(&opt_delayed_start)->default_value(0),
913
       "Delay the startup of threads by a random number of microsends (the maximum of the delay")
914
      ("delimiter,F",po::value<string>(&delimiter)->default_value("\n"),
915
       "Delimiter to use in SQL statements supplied in file or command line")
916
      ("engine ,e",po::value<string>(&default_engine)->default_value(""),
917
       "Storage engien to use for creating the table")
918
      ("set-random-seed",
919
       po::value<uint32_t>(&opt_set_random_seed)->default_value(0), 
920
       "Seed for random number generator (srandom(3)) ") 
921
      ("silent,s",po::value<bool>(&opt_silent)->default_value(false)->zero_tokens(),
922
       "Run program in silent mode - no output. ") 
923
      ("timer-length",po::value<uint32_t>(&opt_timer_length)->default_value(0),
924
       "Require drizzleslap to run each specific test a certain amount of time in seconds")  
925
      ;
926
927
    po::options_description client_options("Options specific to the client");
928
    client_options.add_options()
929
      ("host,h",po::value<string>(&host)->default_value("localhost"),"Connect to the host")
930
      ("password,P",po::value<char *>(&password),
931
       "Password to use when connecting to server. If password is not given it's asked from the tty")
932
      ("port,p",po::value<uint32_t>(), "Port number to use for connection")
1745.2.1 by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar.
933
      ("protocol",po::value<string>(&opt_protocol)->default_value("mysql"),
934
       "The protocol of connection (mysql or drizzle).")
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
935
      ("user,u",po::value<string>(&user)->default_value(""),
936
       "User for login if not current user")  
937
      ;
938
939
    po::options_description long_options("Allowed Options");
940
    long_options.add(commandline_options).add(slap_options).add(client_options);
941
942
    std::string system_config_dir_slap(SYSCONFDIR); 
943
    system_config_dir_slap.append("/drizzle/drizzleslap.cnf");
944
945
    std::string system_config_dir_client(SYSCONFDIR); 
946
    system_config_dir_client.append("/drizzle/client.cnf");
947
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
948
    std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
949
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
950
    uint64_t temp_drizzle_port= 0;
951
    drizzle_con_st con;
952
    OptionString *eptr;
953
954
955
    po::variables_map vm;
1633.5.2 by Vijay Samuel
Merge fix for password in client/
956
    po::store(po::command_line_parser(argc, argv).options(long_options).
957
            extra_parser(parse_password_arg).run(), vm);
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
958
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
959
    std::string user_config_dir_slap(user_config_dir);
960
    user_config_dir_slap.append("/drizzle/drizzleslap.cnf"); 
961
962
    std::string user_config_dir_client(user_config_dir);
963
    user_config_dir_client.append("/drizzle/client.cnf");
964
965
    ifstream user_slap_ifs(user_config_dir_slap.c_str());
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
966
    po::store(parse_config_file(user_slap_ifs, slap_options), vm);
967
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
968
    ifstream user_client_ifs(user_config_dir_client.c_str());
969
    po::store(parse_config_file(user_client_ifs, client_options), vm);
970
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
971
    ifstream system_slap_ifs(system_config_dir_slap.c_str());
972
    store(parse_config_file(system_slap_ifs, slap_options), vm);
973
974
    ifstream system_client_ifs(system_config_dir_client.c_str());
975
    store(parse_config_file(system_client_ifs, client_options), vm);
976
977
    po::notify(vm);
978
979
    if (process_options())
1531.2.1 by Vijay Samuel
Slap refactored
980
      exit(1);
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
981
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
982
    if ( vm.count("help") || vm.count("info"))
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
983
    {
984
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
985
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
986
      puts("Copyright (C) 2008 Sun Microsystems");
1757.2.15 by Monty Taylor
Fixed a silly quote thing.
987
      puts("This software comes with ABSOLUTELY NO WARRANTY. "
988
           "This is free software,\n"
989
           "and you are welcome to modify and redistribute it under the GPL "
990
           "license\n");
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
991
      puts("Run a query multiple times against the server\n");
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
992
      cout << long_options << endl;
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
993
      exit(0);
994
    }   
995
1745.2.1 by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar.
996
    if (vm.count("protocol"))
997
    {
998
      std::transform(opt_protocol.begin(), opt_protocol.end(),
999
        opt_protocol.begin(), ::tolower);
1000
1001
      if (not opt_protocol.compare("mysql"))
1002
        use_drizzle_protocol=false;
1003
      else if (not opt_protocol.compare("drizzle"))
1004
        use_drizzle_protocol=true;
1005
      else
1006
      {
1007
        cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
1008
        exit(-1);
1009
      }
1010
    }
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
1011
    if (vm.count("port")) 
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1012
    {
1013
      temp_drizzle_port= vm["port"].as<uint32_t>();
1014
1015
      if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
1016
      {
1017
        fprintf(stderr, _("Value supplied for port is not valid.\n"));
1018
        exit(1);
1019
      }
1020
      else
1021
      {
1022
        opt_drizzle_port= (uint32_t) temp_drizzle_port;
1023
      }
1024
    }
1025
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
1026
  if ( vm.count("password") )
1633.5.2 by Vijay Samuel
Merge fix for password in client/
1027
  {
1028
    if (!opt_password.empty())
1029
      opt_password.erase();
1030
    if (password == PASSWORD_SENTINEL)
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1031
    {
1633.5.2 by Vijay Samuel
Merge fix for password in client/
1032
      opt_password= "";
1531.2.1 by Vijay Samuel
Slap refactored
1033
    }
1034
    else
1633.5.2 by Vijay Samuel
Merge fix for password in client/
1035
    {
1036
      opt_password= password;
1037
      tty_password= false;
1038
    }
1039
  }
1040
  else
1041
  {
1042
      tty_password= true;
1043
  }
1044
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1045
1046
1671.2.1 by Vijay Samuel
Merge new user config file processing system.
1047
    if ( vm.count("version") )
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1048
    {
1049
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
1050
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
1051
      exit(0);
1052
    }
1053
1054
    /* Seed the random number generator if we will be using it. */
1055
    if (auto_generate_sql)
1056
    {
1057
      if (opt_set_random_seed == 0)
1058
        opt_set_random_seed= (unsigned int)time(NULL);
1059
      srandom(opt_set_random_seed);
1060
    }
1061
1062
    /* globals? Yes, so we only have to run strlen once */
1063
    delimiter_length= delimiter.length();
1064
1065
    slap_connect(&con, false);
1066
1067
    pthread_mutex_init(&counter_mutex, NULL);
1068
    pthread_cond_init(&count_threshhold, NULL);
1069
    pthread_mutex_init(&sleeper_mutex, NULL);
1070
    pthread_cond_init(&sleep_threshhold, NULL);
1071
    pthread_mutex_init(&timer_alarm_mutex, NULL);
1072
    pthread_cond_init(&timer_alarm_threshold, NULL);
1073
1074
1075
    /* Main iterations loop */
1076
burnin:
1077
    eptr= engine_options;
1078
    do
1079
    {
1080
      /* For the final stage we run whatever queries we were asked to run */
1081
      uint32_t *current;
1082
1083
      if (verbose >= 2)
1084
        printf("Starting Concurrency Test\n");
1085
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
1086
      if (concurrency.size())
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1087
      {
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
1088
        for (current= &concurrency[0]; current && *current; current++)
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1089
          concurrency_loop(&con, *current, eptr);
1090
      }
1091
      else
1092
      {
1093
        uint32_t infinite= 1;
1094
        do {
1095
          concurrency_loop(&con, infinite, eptr);
1096
        }
1097
        while (infinite++);
1098
      }
1099
1100
      if (!opt_preserve)
1101
        drop_schema(&con, create_schema_string.c_str());
1102
1103
    } while (eptr ? (eptr= eptr->getNext()) : 0);
1104
1105
    if (opt_burnin)
1106
      goto burnin;
1107
1108
    pthread_mutex_destroy(&counter_mutex);
1109
    pthread_cond_destroy(&count_threshhold);
1110
    pthread_mutex_destroy(&sleeper_mutex);
1111
    pthread_cond_destroy(&sleep_threshhold);
1112
    pthread_mutex_destroy(&timer_alarm_mutex);
1113
    pthread_cond_destroy(&timer_alarm_threshold);
1114
1115
    slap_close(&con);
1116
1117
    /* now free all the strings we created */
1531.2.4 by Vijay Samuel
Updated Slap
1118
    if (!opt_password.empty())
1531.2.2 by Vijay Samuel
Updated slap code
1119
      opt_password.erase();
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1120
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
1121
    concurrency.clear();
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1122
1123
    statement_cleanup(create_statements);
1707.1.17 by Brian Aker
REmove malloc() for vector.
1124
    for (uint32_t x= 0; x < query_statements_count; x++)
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1125
      statement_cleanup(query_statements[x]);
1707.1.17 by Brian Aker
REmove malloc() for vector.
1126
    query_statements.clear();
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1127
    statement_cleanup(pre_statements);
1128
    statement_cleanup(post_statements);
1129
    option_cleanup(engine_options);
1130
    option_cleanup(query_options);
1 by brian
clean slate
1131
1132
#ifdef HAVE_SMEM
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1133
    if (shared_memory_base_name)
1134
      free(shared_memory_base_name);
1 by brian
clean slate
1135
#endif
1531.2.27 by Vijay Samuel
Slap completely refactored with boost::program_options.
1136
1531.2.7 by Vijay Samuel
updated slap
1137
  }
1 by brian
clean slate
1138
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1139
  catch(std::exception &err)
1531.2.7 by Vijay Samuel
updated slap
1140
  {
1627.2.8 by Monty Taylor
Fixed drizzleslap build issue on Solaris.
1141
    cerr<<"Error:"<<err.what()<<endl;
1531.2.7 by Vijay Samuel
updated slap
1142
  }
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1143
1144
  if (csv_file != fileno(stdout))
1145
    close(csv_file);
1146
1 by brian
clean slate
1147
  return 0;
1148
}
1149
1441.3.1 by Vijay Samuel
all required updations have been made
1150
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr)
1 by brian
clean slate
1151
{
1441.3.1 by Vijay Samuel
all required updations have been made
1152
  Stats *head_sptr;
1153
  Stats *sptr;
1154
  Conclusions conclusion;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
1155
  uint64_t client_limit;
1 by brian
clean slate
1156
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1157
  head_sptr= new Stats[iterations];
656.1.45 by Monty Taylor
Added null return checks to mallocs in drizzleslap.
1158
  if (head_sptr == NULL)
1159
  {
1160
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
1161
    exit(1);
1162
  }
1 by brian
clean slate
1163
1164
  if (auto_actual_queries)
1165
    client_limit= auto_actual_queries;
1166
  else if (num_of_query)
1167
    client_limit=  num_of_query / current;
1168
  else
1169
    client_limit= actual_queries;
1170
1707.1.18 by Brian Aker
Style cleanups.
1171
  uint32_t x;
1 by brian
clean slate
1172
  for (x= 0, sptr= head_sptr; x < iterations; x++, sptr++)
1173
  {
1174
    /*
1175
      We might not want to load any data, such as when we are calling
1176
      a stored_procedure that doesn't use data, or we know we already have
1177
      data in the table.
1178
    */
163 by Brian Aker
Merge Monty's code.
1179
    if (opt_preserve == false)
1531.2.1 by Vijay Samuel
Slap refactored
1180
      drop_schema(con, create_schema_string.c_str());
1 by brian
clean slate
1181
1182
    /* First we create */
1183
    if (create_statements)
1531.2.1 by Vijay Samuel
Slap refactored
1184
      create_schema(con, create_schema_string.c_str(), create_statements, eptr, sptr);
1 by brian
clean slate
1185
1186
    /*
1187
      If we generated GUID we need to build a list of them from creation that
1188
      we can later use.
1189
    */
1190
    if (verbose >= 2)
1191
      printf("Generating primary key list\n");
1192
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
1193
      generate_primary_key_list(con, eptr);
1 by brian
clean slate
1194
1195
    if (commit_rate)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
1196
      run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
1 by brian
clean slate
1197
1531.2.4 by Vijay Samuel
Updated Slap
1198
    if (!pre_system.empty())
1090.1.3 by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart.
1199
    {
1531.2.2 by Vijay Samuel
Updated slap code
1200
      int ret= system(pre_system.c_str());
1090.1.3 by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart.
1201
      assert(ret != -1);
1202
    }
1203
       
1 by brian
clean slate
1204
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1205
    /*
1206
      Pre statements are always run after all other logic so they can
1207
      correct/adjust any item that they want.
1 by brian
clean slate
1208
    */
1209
    if (pre_statements)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
1210
      run_statements(con, pre_statements);
1 by brian
clean slate
1211
1707.1.17 by Brian Aker
REmove malloc() for vector.
1212
    run_scheduler(sptr, &query_statements[0], current, client_limit);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1213
1 by brian
clean slate
1214
    if (post_statements)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
1215
      run_statements(con, post_statements);
1 by brian
clean slate
1216
1531.2.4 by Vijay Samuel
Updated Slap
1217
    if (!post_system.empty())
1090.1.3 by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart.
1218
    {
1531.2.2 by Vijay Samuel
Updated slap code
1219
      int ret=  system(post_system.c_str());
1090.1.3 by Monty Taylor
Removed dangerous asserts... mainly to upset Stewart.
1220
      assert(ret !=-1);
1221
    }
1 by brian
clean slate
1222
1223
    /* We are finished with this run */
1224
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1707.1.11 by Brian Aker
Move primary_keys to being a vector.
1225
      primary_keys.clear();
1 by brian
clean slate
1226
  }
1227
1228
  if (verbose >= 2)
1229
    printf("Generating stats\n");
1230
1231
  generate_stats(&conclusion, eptr, head_sptr);
1232
1233
  if (!opt_silent)
1234
    print_conclusions(&conclusion);
1531.2.4 by Vijay Samuel
Updated Slap
1235
  if (!opt_csv_str.empty())
1 by brian
clean slate
1236
    print_conclusions_csv(&conclusion);
1237
1707.1.14 by Brian Aker
Remove valgrind warning.
1238
  delete [] head_sptr;
1 by brian
clean slate
1239
}
1240
1241
1242
uint
1243
get_random_string(char *buf, size_t size)
1244
{
1245
  char *buf_ptr= buf;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1246
1707.1.18 by Brian Aker
Style cleanups.
1247
  for (size_t x= size; x > 0; x--)
1 by brian
clean slate
1248
    *buf_ptr++= ALPHANUMERICS[random() % ALPHANUMERICS_SIZE];
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1249
  return(buf_ptr - buf);
1 by brian
clean slate
1250
}
1251
1252
1253
/*
1254
  build_table_string
1255
1256
  This function builds a create table query if the user opts to not supply
1257
  a file or string containing a create table statement
1258
*/
1441.3.1 by Vijay Samuel
all required updations have been made
1259
static Statement *
1 by brian
clean slate
1260
build_table_string(void)
1261
{
1262
  char       buf[HUGE_STRING_LENGTH];
1263
  unsigned int        col_count;
1441.3.1 by Vijay Samuel
all required updations have been made
1264
  Statement *ptr;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1265
  string table_string;
1266
1267
  table_string.reserve(HUGE_STRING_LENGTH);
1268
1269
  table_string= "CREATE TABLE `t1` (";
1 by brian
clean slate
1270
1271
  if (auto_generate_sql_autoincrement)
1272
  {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1273
    table_string.append("id serial");
1 by brian
clean slate
1274
1275
    if (num_int_cols || num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1276
      table_string.append(",");
1 by brian
clean slate
1277
  }
1278
1279
  if (auto_generate_sql_guid_primary)
1280
  {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1281
    table_string.append("id varchar(128) primary key");
1 by brian
clean slate
1282
1283
    if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1284
      table_string.append(",");
1 by brian
clean slate
1285
  }
1286
1287
  if (auto_generate_sql_secondary_indexes)
1288
  {
1289
    unsigned int count;
1290
1291
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1292
    {
1293
      if (count) /* Except for the first pass we add a comma */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1294
        table_string.append(",");
1 by brian
clean slate
1295
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1296
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
1 by brian
clean slate
1297
          > HUGE_STRING_LENGTH)
1298
      {
1299
        fprintf(stderr, "Memory Allocation error in create table\n");
1300
        exit(1);
1301
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1302
      table_string.append(buf);
1 by brian
clean slate
1303
    }
1304
1305
    if (num_int_cols || num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1306
      table_string.append(",");
1 by brian
clean slate
1307
  }
1308
1309
  if (num_int_cols)
1310
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1311
    {
1312
      if (num_int_cols_index)
1313
      {
223 by Brian Aker
Cleanup int() work.
1314
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT, INDEX(intcol%d)",
1 by brian
clean slate
1315
                     col_count, col_count) > HUGE_STRING_LENGTH)
1316
        {
1317
          fprintf(stderr, "Memory Allocation error in create table\n");
1318
          exit(1);
1319
        }
1320
      }
1321
      else
1322
      {
223 by Brian Aker
Cleanup int() work.
1323
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT ", col_count)
1 by brian
clean slate
1324
            > HUGE_STRING_LENGTH)
1325
        {
1326
          fprintf(stderr, "Memory Allocation error in create table\n");
1327
          exit(1);
1328
        }
1329
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1330
      table_string.append(buf);
1 by brian
clean slate
1331
1332
      if (col_count < num_int_cols || num_char_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1333
        table_string.append(",");
1 by brian
clean slate
1334
    }
1335
1336
  if (num_char_cols)
1337
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1338
    {
1339
      if (num_char_cols_index)
1340
      {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1341
        if (snprintf(buf, HUGE_STRING_LENGTH,
1342
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ",
1 by brian
clean slate
1343
                     col_count, col_count) > HUGE_STRING_LENGTH)
1344
        {
1345
          fprintf(stderr, "Memory Allocation error in creating table\n");
1346
          exit(1);
1347
        }
1348
      }
1349
      else
1350
      {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1351
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)",
1 by brian
clean slate
1352
                     col_count) > HUGE_STRING_LENGTH)
1353
        {
1354
          fprintf(stderr, "Memory Allocation error in creating table\n");
1355
          exit(1);
1356
        }
1357
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1358
      table_string.append(buf);
1 by brian
clean slate
1359
1360
      if (col_count < num_char_cols || num_blob_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1361
        table_string.append(",");
1 by brian
clean slate
1362
    }
1363
1364
  if (num_blob_cols)
1365
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1366
    {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1367
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob",
1 by brian
clean slate
1368
                   col_count) > HUGE_STRING_LENGTH)
1369
      {
1370
        fprintf(stderr, "Memory Allocation error in creating table\n");
1371
        exit(1);
1372
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1373
      table_string.append(buf);
1 by brian
clean slate
1374
1375
      if (col_count < num_blob_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1376
        table_string.append(",");
1 by brian
clean slate
1377
    }
1378
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1379
  table_string.append(")");
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1380
  ptr= new Statement;
1707.1.9 by Brian Aker
Partial pass through the string in statement.
1381
  ptr->setString(table_string.length());
1441.3.1 by Vijay Samuel
all required updations have been made
1382
  if (ptr->getString()==NULL)
656.1.45 by Monty Taylor
Added null return checks to mallocs in drizzleslap.
1383
  {
1384
    fprintf(stderr, "Memory Allocation error in creating table\n");
1385
    exit(1);
1386
  }
1441.3.1 by Vijay Samuel
all required updations have been made
1387
  ptr->setType(CREATE_TABLE_TYPE);
1388
  strcpy(ptr->getString(), table_string.c_str());
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1389
  return(ptr);
1 by brian
clean slate
1390
}
1391
1392
/*
1393
  build_update_string()
1394
1395
  This function builds insert statements when the user opts to not supply
1396
  an insert file or string containing insert data
1397
*/
1441.3.1 by Vijay Samuel
all required updations have been made
1398
static Statement *
1 by brian
clean slate
1399
build_update_string(void)
1400
{
1401
  char       buf[HUGE_STRING_LENGTH];
1402
  unsigned int        col_count;
1441.3.1 by Vijay Samuel
all required updations have been made
1403
  Statement *ptr;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1404
  string update_string;
1405
1406
  update_string.reserve(HUGE_STRING_LENGTH);
1407
1408
  update_string= "UPDATE t1 SET ";
1 by brian
clean slate
1409
1410
  if (num_int_cols)
1411
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1412
    {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1413
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count,
1 by brian
clean slate
1414
                   random()) > HUGE_STRING_LENGTH)
1415
      {
1416
        fprintf(stderr, "Memory Allocation error in creating update\n");
1417
        exit(1);
1418
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1419
      update_string.append(buf);
1 by brian
clean slate
1420
1421
      if (col_count < num_int_cols || num_char_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1422
        update_string.append(",", 1);
1 by brian
clean slate
1423
    }
1424
1425
  if (num_char_cols)
1426
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1427
    {
1428
      char rand_buffer[RAND_STRING_SIZE];
1429
      int buf_len= get_random_string(rand_buffer, RAND_STRING_SIZE);
1430
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1431
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count,
1432
                   buf_len, rand_buffer)
1 by brian
clean slate
1433
          > HUGE_STRING_LENGTH)
1434
      {
1435
        fprintf(stderr, "Memory Allocation error in creating update\n");
1436
        exit(1);
1437
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1438
      update_string.append(buf);
1 by brian
clean slate
1439
1440
      if (col_count < num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1441
        update_string.append(",", 1);
1 by brian
clean slate
1442
    }
1443
1444
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1445
    update_string.append(" WHERE id = ");
1 by brian
clean slate
1446
1447
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1448
  ptr= new Statement;
1 by brian
clean slate
1449
1707.1.9 by Brian Aker
Partial pass through the string in statement.
1450
  ptr->setString(update_string.length());
1441.3.1 by Vijay Samuel
all required updations have been made
1451
  if (ptr->getString() == NULL)
656.1.45 by Monty Taylor
Added null return checks to mallocs in drizzleslap.
1452
  {
1453
    fprintf(stderr, "Memory Allocation error in creating update\n");
1454
    exit(1);
1455
  }
1 by brian
clean slate
1456
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1441.3.1 by Vijay Samuel
all required updations have been made
1457
    ptr->setType(UPDATE_TYPE_REQUIRES_PREFIX);
1 by brian
clean slate
1458
  else
1441.3.1 by Vijay Samuel
all required updations have been made
1459
    ptr->setType(UPDATE_TYPE);
1460
  strncpy(ptr->getString(), update_string.c_str(), ptr->getLength());
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1461
  return(ptr);
1 by brian
clean slate
1462
}
1463
1464
1465
/*
1466
  build_insert_string()
1467
1468
  This function builds insert statements when the user opts to not supply
1469
  an insert file or string containing insert data
1470
*/
1441.3.1 by Vijay Samuel
all required updations have been made
1471
static Statement *
1 by brian
clean slate
1472
build_insert_string(void)
1473
{
1474
  char       buf[HUGE_STRING_LENGTH];
1475
  unsigned int        col_count;
1441.3.1 by Vijay Samuel
all required updations have been made
1476
  Statement *ptr;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1477
  string insert_string;
1478
1479
  insert_string.reserve(HUGE_STRING_LENGTH);
1480
1481
  insert_string= "INSERT INTO t1 VALUES (";
1 by brian
clean slate
1482
1483
  if (auto_generate_sql_autoincrement)
1484
  {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1485
    insert_string.append("NULL");
1 by brian
clean slate
1486
1487
    if (num_int_cols || num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1488
      insert_string.append(",");
1 by brian
clean slate
1489
  }
1490
1491
  if (auto_generate_sql_guid_primary)
1492
  {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1493
    insert_string.append("uuid()");
1 by brian
clean slate
1494
1495
    if (num_int_cols || num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1496
      insert_string.append(",");
1 by brian
clean slate
1497
  }
1498
1499
  if (auto_generate_sql_secondary_indexes)
1500
  {
1501
    unsigned int count;
1502
1503
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1504
    {
1505
      if (count) /* Except for the first pass we add a comma */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1506
        insert_string.append(",");
1 by brian
clean slate
1507
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1508
      insert_string.append("uuid()");
1 by brian
clean slate
1509
    }
1510
1511
    if (num_int_cols || num_char_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1512
      insert_string.append(",");
1 by brian
clean slate
1513
  }
1514
1515
  if (num_int_cols)
1516
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1517
    {
1518
      if (snprintf(buf, HUGE_STRING_LENGTH, "%ld", random()) > HUGE_STRING_LENGTH)
1519
      {
1520
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1521
        exit(1);
1522
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1523
      insert_string.append(buf);
1 by brian
clean slate
1524
1525
      if (col_count < num_int_cols || num_char_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1526
        insert_string.append(",");
1 by brian
clean slate
1527
    }
1528
1529
  if (num_char_cols)
1530
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1531
    {
1532
      int buf_len= get_random_string(buf, RAND_STRING_SIZE);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1533
      insert_string.append("'", 1);
1534
      insert_string.append(buf, buf_len);
1535
      insert_string.append("'", 1);
1 by brian
clean slate
1536
1537
      if (col_count < num_char_cols || num_blob_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1538
        insert_string.append(",", 1);
1 by brian
clean slate
1539
    }
1540
1541
  if (num_blob_cols)
1542
  {
1707.1.15 by Brian Aker
New fix in drizzleslap.
1543
    vector <char> blob_ptr;
1 by brian
clean slate
1544
1707.1.15 by Brian Aker
New fix in drizzleslap.
1545
    blob_ptr.resize(num_blob_cols_size);
1 by brian
clean slate
1546
1547
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1548
    {
1549
      unsigned int buf_len;
1550
      unsigned int size;
1551
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1552
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1553
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1554
        num_blob_cols_size;
1 by brian
clean slate
1555
1707.1.15 by Brian Aker
New fix in drizzleslap.
1556
      buf_len= get_random_string(&blob_ptr[0], size);
1 by brian
clean slate
1557
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1558
      insert_string.append("'", 1);
1707.1.15 by Brian Aker
New fix in drizzleslap.
1559
      insert_string.append(&blob_ptr[0], buf_len);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1560
      insert_string.append("'", 1);
1 by brian
clean slate
1561
1562
      if (col_count < num_blob_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1563
        insert_string.append(",", 1);
1 by brian
clean slate
1564
    }
1565
  }
1566
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1567
  insert_string.append(")", 1);
1 by brian
clean slate
1568
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1569
  ptr= new Statement;
1707.1.9 by Brian Aker
Partial pass through the string in statement.
1570
  ptr->setString(insert_string.length());
1441.3.1 by Vijay Samuel
all required updations have been made
1571
  if (ptr->getString()==NULL)
1572
  {
1573
    fprintf(stderr, "Memory Allocation error in creating select\n");
1574
    exit(1);
1575
  }
1576
  ptr->setType(INSERT_TYPE);
1577
  strcpy(ptr->getString(), insert_string.c_str());
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1578
  return(ptr);
1 by brian
clean slate
1579
}
1580
1581
1582
/*
1583
  build_select_string()
1584
1585
  This function builds a query if the user opts to not supply a query
1586
  statement or file containing a query statement
1587
*/
1441.3.1 by Vijay Samuel
all required updations have been made
1588
static Statement *
143 by Brian Aker
Bool cleanup.
1589
build_select_string(bool key)
1 by brian
clean slate
1590
{
1591
  char       buf[HUGE_STRING_LENGTH];
1592
  unsigned int        col_count;
1441.3.1 by Vijay Samuel
all required updations have been made
1593
  Statement *ptr;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1594
  string query_string;
1595
1596
  query_string.reserve(HUGE_STRING_LENGTH);
1597
1598
  query_string.append("SELECT ", 7);
1531.2.4 by Vijay Samuel
Updated Slap
1599
  if (!auto_generate_selected_columns_opt.empty())
1 by brian
clean slate
1600
  {
1531.2.2 by Vijay Samuel
Updated slap code
1601
    query_string.append(auto_generate_selected_columns_opt.c_str());
1 by brian
clean slate
1602
  }
1603
  else
1604
  {
1605
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1606
    {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1607
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count)
1 by brian
clean slate
1608
          > HUGE_STRING_LENGTH)
1609
      {
1610
        fprintf(stderr, "Memory Allocation error in creating select\n");
1611
        exit(1);
1612
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1613
      query_string.append(buf);
1 by brian
clean slate
1614
1615
      if (col_count < num_int_cols || num_char_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1616
        query_string.append(",", 1);
1 by brian
clean slate
1617
1618
    }
1619
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1620
    {
1621
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d", col_count)
1622
          > HUGE_STRING_LENGTH)
1623
      {
1624
        fprintf(stderr, "Memory Allocation error in creating select\n");
1625
        exit(1);
1626
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1627
      query_string.append(buf);
1 by brian
clean slate
1628
1629
      if (col_count < num_char_cols || num_blob_cols > 0)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1630
        query_string.append(",", 1);
1 by brian
clean slate
1631
1632
    }
1633
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1634
    {
1635
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d", col_count)
1636
          > HUGE_STRING_LENGTH)
1637
      {
1638
        fprintf(stderr, "Memory Allocation error in creating select\n");
1639
        exit(1);
1640
      }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1641
      query_string.append(buf);
1 by brian
clean slate
1642
1643
      if (col_count < num_blob_cols)
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1644
        query_string.append(",", 1);
1 by brian
clean slate
1645
    }
1646
  }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1647
  query_string.append(" FROM t1");
1 by brian
clean slate
1648
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1649
  if ((key) &&
1 by brian
clean slate
1650
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1651
    query_string.append(" WHERE id = ");
1 by brian
clean slate
1652
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
1653
  ptr= new Statement;
1707.1.9 by Brian Aker
Partial pass through the string in statement.
1654
  ptr->setString(query_string.length());
1441.3.1 by Vijay Samuel
all required updations have been made
1655
  if (ptr->getString() == NULL)
656.1.45 by Monty Taylor
Added null return checks to mallocs in drizzleslap.
1656
  {
1657
    fprintf(stderr, "Memory Allocation error in creating select\n");
1658
    exit(1);
1659
  }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1660
  if ((key) &&
1 by brian
clean slate
1661
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1441.3.1 by Vijay Samuel
all required updations have been made
1662
    ptr->setType(SELECT_TYPE_REQUIRES_PREFIX);
1 by brian
clean slate
1663
  else
1441.3.1 by Vijay Samuel
all required updations have been made
1664
    ptr->setType(SELECT_TYPE);
1665
  strcpy(ptr->getString(), query_string.c_str());
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1666
  return(ptr);
1 by brian
clean slate
1667
}
1668
1669
static int
1531.2.11 by Vijay Samuel
Refactored command line options for slap using boost::program_options
1670
process_options(void)
1 by brian
clean slate
1671
{
15 by brian
Fix for stat, NETWARE removal
1672
  struct stat sbuf;
1441.3.1 by Vijay Samuel
all required updations have been made
1673
  OptionString *sql_type;
1 by brian
clean slate
1674
  unsigned int sql_type_count= 0;
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1675
  ssize_t bytes_read= 0;
1531.2.1 by Vijay Samuel
Slap refactored
1676
  
1531.2.4 by Vijay Samuel
Updated Slap
1677
  if (user.empty())
1531.2.2 by Vijay Samuel
Updated slap code
1678
    user= "root";
1 by brian
clean slate
1679
1531.2.19 by Vijay Samuel
Refactored command line options for slap using boost::program_options
1680
  verbose= opt_verbose.length();
1531.2.18 by Vijay Samuel
Refactored command line options for slap using boost::program_options
1681
1 by brian
clean slate
1682
  /* If something is created we clean it up, otherwise we leave schemas alone */
1531.2.4 by Vijay Samuel
Updated Slap
1683
  if ( (!create_string.empty()) || auto_generate_sql)
163 by Brian Aker
Merge Monty's code.
1684
    opt_preserve= false;
1 by brian
clean slate
1685
1531.2.4 by Vijay Samuel
Updated Slap
1686
  if (auto_generate_sql && (!create_string.empty() || !user_supplied_query.empty()))
1 by brian
clean slate
1687
  {
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1688
    fprintf(stderr,
1689
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1690
            internal::my_progname);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1691
    exit(1);
1 by brian
clean slate
1692
  }
1693
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1694
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1 by brian
clean slate
1695
      auto_generate_sql_autoincrement)
1696
  {
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1697
    fprintf(stderr,
1698
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1699
            internal::my_progname);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1700
    exit(1);
1 by brian
clean slate
1701
  }
1702
1703
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1704
  {
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1705
    fprintf(stderr,
1706
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1707
            internal::my_progname);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1708
    exit(1);
1 by brian
clean slate
1709
  }
1710
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
1711
  parse_comma(!concurrency_str.empty() ? concurrency_str.c_str() : "1", concurrency);
1 by brian
clean slate
1712
1531.2.4 by Vijay Samuel
Updated Slap
1713
  if (!opt_csv_str.empty())
1 by brian
clean slate
1714
  {
163 by Brian Aker
Merge Monty's code.
1715
    opt_silent= true;
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
1716
1 by brian
clean slate
1717
    if (opt_csv_str[0] == '-')
1718
    {
1719
      csv_file= fileno(stdout);
1720
    }
1721
    else
1722
    {
1531.2.1 by Vijay Samuel
Slap refactored
1723
      if ((csv_file= open(opt_csv_str.c_str(), O_CREAT|O_WRONLY|O_APPEND, 
1054.2.8 by Monty Taylor
Fixed staging build issue.
1724
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1 by brian
clean slate
1725
      {
1726
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1531.2.1 by Vijay Samuel
Slap refactored
1727
                internal::my_progname, opt_csv_str.c_str());
1 by brian
clean slate
1728
        exit(1);
1729
      }
1730
    }
1731
  }
1732
1733
  if (opt_only_print)
163 by Brian Aker
Merge Monty's code.
1734
    opt_silent= true;
1 by brian
clean slate
1735
1531.2.8 by Vijay Samuel
Updated Slap
1736
  if (!num_int_cols_opt.empty())
1737
  {
1738
    OptionString *str;
1739
    parse_option(num_int_cols_opt.c_str(), &str, ',');
1740
    num_int_cols= atoi(str->getString());
1741
    if (str->getOption())
1742
      num_int_cols_index= atoi(str->getOption());
1743
    option_cleanup(str);
1744
  }
1531.2.1 by Vijay Samuel
Slap refactored
1745
1531.2.8 by Vijay Samuel
Updated Slap
1746
  if (!num_char_cols_opt.empty())
1747
  {
1748
    OptionString *str;
1749
    parse_option(num_char_cols_opt.c_str(), &str, ',');
1750
    num_char_cols= atoi(str->getString());
1751
    if (str->getOption())
1752
      num_char_cols_index= atoi(str->getOption());
1753
    else
1754
      num_char_cols_index= 0;
1755
    option_cleanup(str);
1756
  }
1531.2.1 by Vijay Samuel
Slap refactored
1757
1531.2.4 by Vijay Samuel
Updated Slap
1758
  if (!num_blob_cols_opt.empty())
1531.2.1 by Vijay Samuel
Slap refactored
1759
  {
1760
    OptionString *str;
1761
    parse_option(num_blob_cols_opt.c_str(), &str, ',');
1441.3.1 by Vijay Samuel
all required updations have been made
1762
    num_blob_cols= atoi(str->getString());
1763
    if (str->getOption())
1 by brian
clean slate
1764
    {
1765
      char *sep_ptr;
1766
1441.3.1 by Vijay Samuel
all required updations have been made
1767
      if ((sep_ptr= strchr(str->getOption(), '/')))
1 by brian
clean slate
1768
      {
1441.3.1 by Vijay Samuel
all required updations have been made
1769
        num_blob_cols_size_min= atoi(str->getOption());
1 by brian
clean slate
1770
        num_blob_cols_size= atoi(sep_ptr+1);
1771
      }
1772
      else
1773
      {
1441.3.1 by Vijay Samuel
all required updations have been made
1774
        num_blob_cols_size_min= num_blob_cols_size= atoi(str->getOption());
1 by brian
clean slate
1775
      }
1776
    }
1777
    else
1778
    {
1779
      num_blob_cols_size= DEFAULT_BLOB_SIZE;
1780
      num_blob_cols_size_min= DEFAULT_BLOB_SIZE;
1781
    }
1782
    option_cleanup(str);
1783
  }
1784
1785
1786
  if (auto_generate_sql)
1787
  {
398.1.8 by Monty Taylor
Enabled -Wlong-long.
1788
    uint64_t x= 0;
1441.3.1 by Vijay Samuel
all required updations have been made
1789
    Statement *ptr_statement;
1 by brian
clean slate
1790
1791
    if (verbose >= 2)
1792
      printf("Building Create Statements for Auto\n");
1793
1794
    create_statements= build_table_string();
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1795
    /*
1796
      Pre-populate table
1 by brian
clean slate
1797
    */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1798
    for (ptr_statement= create_statements, x= 0;
1799
         x < auto_generate_sql_unique_write_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1800
         x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1801
    {
1441.3.1 by Vijay Samuel
all required updations have been made
1802
      ptr_statement->setNext(build_insert_string());
1 by brian
clean slate
1803
    }
1804
1805
    if (verbose >= 2)
1806
      printf("Building Query Statements for Auto\n");
1807
1531.2.4 by Vijay Samuel
Updated Slap
1808
    if (opt_auto_generate_sql_type.empty())
1 by brian
clean slate
1809
      opt_auto_generate_sql_type= "mixed";
1810
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1811
    query_statements_count=
1531.2.1 by Vijay Samuel
Slap refactored
1812
      parse_option(opt_auto_generate_sql_type.c_str(), &query_options, ',');
1 by brian
clean slate
1813
1707.1.17 by Brian Aker
REmove malloc() for vector.
1814
    query_statements.resize(query_statements_count);
1 by brian
clean slate
1815
1816
    sql_type= query_options;
1817
    do
1818
    {
1441.3.1 by Vijay Samuel
all required updations have been made
1819
      if (sql_type->getString()[0] == 'r')
1 by brian
clean slate
1820
      {
1821
        if (verbose >= 2)
1822
          printf("Generating SELECT Statements for Auto\n");
1823
163 by Brian Aker
Merge Monty's code.
1824
        query_statements[sql_type_count]= build_select_string(false);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1825
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1826
             x < auto_generate_sql_unique_query_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1827
             x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1828
        {
1441.3.1 by Vijay Samuel
all required updations have been made
1829
          ptr_statement->setNext(build_select_string(false));
1 by brian
clean slate
1830
        }
1831
      }
1441.3.1 by Vijay Samuel
all required updations have been made
1832
      else if (sql_type->getString()[0] == 'k')
1 by brian
clean slate
1833
      {
1834
        if (verbose >= 2)
1835
          printf("Generating SELECT for keys Statements for Auto\n");
1836
163 by Brian Aker
Merge Monty's code.
1837
        if ( auto_generate_sql_autoincrement == false &&
1838
             auto_generate_sql_guid_primary == false)
1 by brian
clean slate
1839
        {
1840
          fprintf(stderr,
1841
                  "%s: Can't perform key test without a primary key!\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1842
                  internal::my_progname);
1 by brian
clean slate
1843
          exit(1);
1844
        }
1845
163 by Brian Aker
Merge Monty's code.
1846
        query_statements[sql_type_count]= build_select_string(true);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1847
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1848
             x < auto_generate_sql_unique_query_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1849
             x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1850
        {
1441.3.1 by Vijay Samuel
all required updations have been made
1851
          ptr_statement->setNext(build_select_string(true));
1 by brian
clean slate
1852
        }
1853
      }
1441.3.1 by Vijay Samuel
all required updations have been made
1854
      else if (sql_type->getString()[0] == 'w')
1 by brian
clean slate
1855
      {
1856
        /*
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1857
          We generate a number of strings in case the engine is
1 by brian
clean slate
1858
          Archive (since strings which were identical one after another
1859
          would be too easily optimized).
1860
        */
1861
        if (verbose >= 2)
1862
          printf("Generating INSERT Statements for Auto\n");
1863
        query_statements[sql_type_count]= build_insert_string();
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1864
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1865
             x < auto_generate_sql_unique_query_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1866
             x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1867
        {
1441.3.1 by Vijay Samuel
all required updations have been made
1868
          ptr_statement->setNext(build_insert_string());
1 by brian
clean slate
1869
        }
1870
      }
1441.3.1 by Vijay Samuel
all required updations have been made
1871
      else if (sql_type->getString()[0] == 'u')
1 by brian
clean slate
1872
      {
163 by Brian Aker
Merge Monty's code.
1873
        if ( auto_generate_sql_autoincrement == false &&
1874
             auto_generate_sql_guid_primary == false)
1 by brian
clean slate
1875
        {
1876
          fprintf(stderr,
1877
                  "%s: Can't perform update test without a primary key!\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1878
                  internal::my_progname);
1 by brian
clean slate
1879
          exit(1);
1880
        }
1881
1882
        query_statements[sql_type_count]= build_update_string();
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1883
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1884
             x < auto_generate_sql_unique_query_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1885
             x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1886
        {
1441.3.1 by Vijay Samuel
all required updations have been made
1887
          ptr_statement->setNext(build_update_string());
1 by brian
clean slate
1888
        }
1889
      }
1890
      else /* Mixed mode is default */
1891
      {
1892
        int coin= 0;
1893
1894
        query_statements[sql_type_count]= build_insert_string();
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1895
        /*
1 by brian
clean slate
1896
          This logic should be extended to do a more mixed load,
1897
          at the moment it results in "every other".
1898
        */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1899
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1900
             x < auto_generate_sql_unique_query_number;
1441.3.1 by Vijay Samuel
all required updations have been made
1901
             x++, ptr_statement= ptr_statement->getNext())
1 by brian
clean slate
1902
        {
1903
          if (coin)
1904
          {
1441.3.1 by Vijay Samuel
all required updations have been made
1905
            ptr_statement->setNext(build_insert_string());
1 by brian
clean slate
1906
            coin= 0;
1907
          }
1908
          else
1909
          {
1441.3.1 by Vijay Samuel
all required updations have been made
1910
            ptr_statement->setNext(build_select_string(true));
1 by brian
clean slate
1911
            coin= 1;
1912
          }
1913
        }
1914
      }
1915
      sql_type_count++;
1441.3.1 by Vijay Samuel
all required updations have been made
1916
    } while (sql_type ? (sql_type= sql_type->getNext()) : 0);
1 by brian
clean slate
1917
  }
1918
  else
1919
  {
1531.2.4 by Vijay Samuel
Updated Slap
1920
    if (!create_string.empty() && !stat(create_string.c_str(), &sbuf))
1 by brian
clean slate
1921
    {
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1922
      int data_file;
1707.1.10 by Brian Aker
Further memory cleanup
1923
      std::vector<char> tmp_string;
212.5.37 by Monty Taylor
Removed my_stat.
1924
      if (!S_ISREG(sbuf.st_mode))
1 by brian
clean slate
1925
      {
1926
        fprintf(stderr,"%s: Create file was not a regular file\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1927
                internal::my_progname);
1 by brian
clean slate
1928
        exit(1);
1929
      }
1531.2.3 by Vijay Samuel
Updated Slap code
1930
      if ((data_file= open(create_string.c_str(), O_RDWR)) == -1)
1 by brian
clean slate
1931
      {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1932
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
1 by brian
clean slate
1933
        exit(1);
1934
      }
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1935
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
1936
      {
1937
        fprintf(stderr, "Request for more memory than architecture supports\n");
1938
        exit(1);
1939
      }
1707.1.10 by Brian Aker
Further memory cleanup
1940
      tmp_string.resize(sbuf.st_size + 1);
1941
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1942
                       (size_t)sbuf.st_size);
1014.8.4 by Toru Maesaka
Replace occrrences of my_(open|close) with straight open() and close() system calls
1943
      close(data_file);
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1944
      if (bytes_read != sbuf.st_size)
1945
      {
1946
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1947
      }
1707.1.10 by Brian Aker
Further memory cleanup
1948
      parse_delimiter(&tmp_string[0], &create_statements, delimiter[0]);
1 by brian
clean slate
1949
    }
1531.2.4 by Vijay Samuel
Updated Slap
1950
    else if (!create_string.empty())
1 by brian
clean slate
1951
    {
1531.2.3 by Vijay Samuel
Updated Slap code
1952
      parse_delimiter(create_string.c_str(), &create_statements, delimiter[0]);
1 by brian
clean slate
1953
    }
1954
1955
    /* Set this up till we fully support options on user generated queries */
1531.2.4 by Vijay Samuel
Updated Slap
1956
    if (!user_supplied_query.empty())
1 by brian
clean slate
1957
    {
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1958
      query_statements_count=
1 by brian
clean slate
1959
        parse_option("default", &query_options, ',');
1960
1707.1.17 by Brian Aker
REmove malloc() for vector.
1961
      query_statements.resize(query_statements_count);
1 by brian
clean slate
1962
    }
1963
1531.2.4 by Vijay Samuel
Updated Slap
1964
    if (!user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
1 by brian
clean slate
1965
    {
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
1966
      int data_file;
1707.1.10 by Brian Aker
Further memory cleanup
1967
      std::vector<char> tmp_string;
1968
212.5.37 by Monty Taylor
Removed my_stat.
1969
      if (!S_ISREG(sbuf.st_mode))
1 by brian
clean slate
1970
      {
1971
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1972
                internal::my_progname);
1 by brian
clean slate
1973
        exit(1);
1974
      }
1531.2.2 by Vijay Samuel
Updated slap code
1975
      if ((data_file= open(user_supplied_query.c_str(), O_RDWR)) == -1)
1 by brian
clean slate
1976
      {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1977
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1 by brian
clean slate
1978
        exit(1);
1979
      }
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1980
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
1981
      {
1982
        fprintf(stderr, "Request for more memory than architecture supports\n");
1983
        exit(1);
1984
      }
1707.1.10 by Brian Aker
Further memory cleanup
1985
      tmp_string.resize((size_t)(sbuf.st_size + 1));
1986
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1987
                       (size_t)sbuf.st_size);
1014.8.4 by Toru Maesaka
Replace occrrences of my_(open|close) with straight open() and close() system calls
1988
      close(data_file);
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
1989
      if (bytes_read != sbuf.st_size)
1990
      {
1991
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1992
      }
1531.2.4 by Vijay Samuel
Updated Slap
1993
      if (!user_supplied_query.empty())
1707.1.10 by Brian Aker
Further memory cleanup
1994
        actual_queries= parse_delimiter(&tmp_string[0], &query_statements[0],
1 by brian
clean slate
1995
                                        delimiter[0]);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
1996
    }
1531.2.4 by Vijay Samuel
Updated Slap
1997
    else if (!user_supplied_query.empty())
1 by brian
clean slate
1998
    {
1531.2.2 by Vijay Samuel
Updated slap code
1999
      actual_queries= parse_delimiter(user_supplied_query.c_str(), &query_statements[0],
1 by brian
clean slate
2000
                                      delimiter[0]);
2001
    }
2002
  }
2003
1531.2.4 by Vijay Samuel
Updated Slap
2004
  if (!user_supplied_pre_statements.empty()
1531.2.2 by Vijay Samuel
Updated slap code
2005
      && !stat(user_supplied_pre_statements.c_str(), &sbuf))
1 by brian
clean slate
2006
  {
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
2007
    int data_file;
1707.1.10 by Brian Aker
Further memory cleanup
2008
    std::vector<char> tmp_string;
2009
212.5.37 by Monty Taylor
Removed my_stat.
2010
    if (!S_ISREG(sbuf.st_mode))
1 by brian
clean slate
2011
    {
2012
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2013
              internal::my_progname);
1 by brian
clean slate
2014
      exit(1);
2015
    }
1531.2.2 by Vijay Samuel
Updated slap code
2016
    if ((data_file= open(user_supplied_pre_statements.c_str(), O_RDWR)) == -1)
1 by brian
clean slate
2017
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2018
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1 by brian
clean slate
2019
      exit(1);
2020
    }
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2021
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2022
    {
2023
      fprintf(stderr, "Request for more memory than architecture supports\n");
2024
      exit(1);
2025
    }
1707.1.10 by Brian Aker
Further memory cleanup
2026
    tmp_string.resize((size_t)(sbuf.st_size + 1));
2027
    bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2028
                     (size_t)sbuf.st_size);
1014.8.4 by Toru Maesaka
Replace occrrences of my_(open|close) with straight open() and close() system calls
2029
    close(data_file);
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2030
    if (bytes_read != sbuf.st_size)
2031
    {
2032
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
2033
    }
1531.2.4 by Vijay Samuel
Updated Slap
2034
    if (!user_supplied_pre_statements.empty())
1707.1.10 by Brian Aker
Further memory cleanup
2035
      (void)parse_delimiter(&tmp_string[0], &pre_statements,
1 by brian
clean slate
2036
                            delimiter[0]);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2037
  }
1531.2.4 by Vijay Samuel
Updated Slap
2038
  else if (!user_supplied_pre_statements.empty())
1 by brian
clean slate
2039
  {
1531.2.2 by Vijay Samuel
Updated slap code
2040
    (void)parse_delimiter(user_supplied_pre_statements.c_str(),
1 by brian
clean slate
2041
                          &pre_statements,
2042
                          delimiter[0]);
2043
  }
2044
1531.2.4 by Vijay Samuel
Updated Slap
2045
  if (!user_supplied_post_statements.empty()
1531.2.2 by Vijay Samuel
Updated slap code
2046
      && !stat(user_supplied_post_statements.c_str(), &sbuf))
1 by brian
clean slate
2047
  {
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
2048
    int data_file;
1707.1.10 by Brian Aker
Further memory cleanup
2049
    std::vector<char> tmp_string;
2050
212.5.37 by Monty Taylor
Removed my_stat.
2051
    if (!S_ISREG(sbuf.st_mode))
1 by brian
clean slate
2052
    {
2053
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2054
              internal::my_progname);
1 by brian
clean slate
2055
      exit(1);
2056
    }
1531.2.2 by Vijay Samuel
Updated slap code
2057
    if ((data_file= open(user_supplied_post_statements.c_str(), O_RDWR)) == -1)
1 by brian
clean slate
2058
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2059
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
1 by brian
clean slate
2060
      exit(1);
2061
    }
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2062
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2063
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2064
    {
2065
      fprintf(stderr, "Request for more memory than architecture supports\n");
2066
      exit(1);
2067
    }
1707.1.10 by Brian Aker
Further memory cleanup
2068
    tmp_string.resize((size_t)(sbuf.st_size + 1));
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2069
1707.1.10 by Brian Aker
Further memory cleanup
2070
    bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2071
                     (size_t)(sbuf.st_size));
1014.8.4 by Toru Maesaka
Replace occrrences of my_(open|close) with straight open() and close() system calls
2072
    close(data_file);
779.3.21 by Monty Taylor
Fixed solaris fixes for linux. Oh, and I also seem to have fixed some more configure stuff.
2073
    if (bytes_read != sbuf.st_size)
2074
    {
2075
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
2076
    }
1531.2.4 by Vijay Samuel
Updated Slap
2077
    if (!user_supplied_post_statements.empty())
1707.1.10 by Brian Aker
Further memory cleanup
2078
      (void)parse_delimiter(&tmp_string[0], &post_statements,
1 by brian
clean slate
2079
                            delimiter[0]);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2080
  }
1531.2.4 by Vijay Samuel
Updated Slap
2081
  else if (!user_supplied_post_statements.empty())
1 by brian
clean slate
2082
  {
1531.2.2 by Vijay Samuel
Updated slap code
2083
    (void)parse_delimiter(user_supplied_post_statements.c_str(), &post_statements,
1 by brian
clean slate
2084
                          delimiter[0]);
2085
  }
2086
2087
  if (verbose >= 2)
2088
    printf("Parsing engines to use.\n");
2089
1531.2.4 by Vijay Samuel
Updated Slap
2090
  if (!default_engine.empty())
1531.2.2 by Vijay Samuel
Updated slap code
2091
    parse_option(default_engine.c_str(), &engine_options, ',');
1 by brian
clean slate
2092
2093
  if (tty_password)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2094
    opt_password= client_get_tty_password(NULL);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2095
  return(0);
1 by brian
clean slate
2096
}
2097
2098
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2099
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
2100
                     const char *query, int len)
1 by brian
clean slate
2101
{
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2102
  drizzle_return_t ret;
2103
  drizzle_result_st result_buffer;
2104
1 by brian
clean slate
2105
  if (opt_only_print)
2106
  {
2107
    printf("%.*s;\n", len, query);
2108
    return 0;
2109
  }
2110
2111
  if (verbose >= 3)
2112
    printf("%.*s;\n", len, query);
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2113
2114
  if (result == NULL)
2115
    result= &result_buffer;
2116
2117
  result= drizzle_query(con, result, query, len, &ret);
2118
2119
  if (ret == DRIZZLE_RETURN_OK)
2120
    ret= drizzle_result_buffer(result);
2121
2122
  if (result == &result_buffer)
2123
    drizzle_result_free(result);
2124
    
2125
  return ret;
1 by brian
clean slate
2126
}
2127
2128
2129
static int
1441.3.1 by Vijay Samuel
all required updations have been made
2130
generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt)
1 by brian
clean slate
2131
{
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2132
  drizzle_result_st result;
2133
  drizzle_row_t row;
398.1.8 by Monty Taylor
Enabled -Wlong-long.
2134
  uint64_t counter;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2135
1 by brian
clean slate
2136
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2137
  /*
2138
    Blackhole is a special case, this allows us to test the upper end
1 by brian
clean slate
2139
    of the server during load runs.
2140
  */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2141
  if (opt_only_print || (engine_stmt &&
1441.3.1 by Vijay Samuel
all required updations have been made
2142
                         strstr(engine_stmt->getString(), "blackhole")))
1 by brian
clean slate
2143
  {
2144
    /* Yes, we strdup a const string to simplify the interface */
1707.1.11 by Brian Aker
Move primary_keys to being a vector.
2145
    primary_keys.push_back("796c4422-1d94-102a-9d6d-00e0812d");
1 by brian
clean slate
2146
  }
2147
  else
2148
  {
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2149
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1 by brian
clean slate
2150
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2151
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2152
              drizzle_con_error(con));
1 by brian
clean slate
2153
      exit(1);
2154
    }
2155
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2156
    uint64_t num_rows_ret= drizzle_result_row_count(&result);
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2157
    if (num_rows_ret > SIZE_MAX)
2158
    {
2159
      fprintf(stderr, "More primary keys than than architecture supports\n");
2160
      exit(1);
2161
    }
1707.1.12 by Brian Aker
Remove global for size around primary keys.
2162
    size_t primary_keys_number_of;
779.3.15 by Monty Taylor
Fixed 32-64bit bugs in drizzleslap.
2163
    primary_keys_number_of= (size_t)num_rows_ret;
1 by brian
clean slate
2164
2165
    /* So why check this? Blackhole :) */
2166
    if (primary_keys_number_of)
2167
    {
2168
      /*
2169
        We create the structure and loop and create the items.
2170
      */
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2171
      row= drizzle_row_next(&result);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2172
      for (counter= 0; counter < primary_keys_number_of;
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2173
           counter++, row= drizzle_row_next(&result))
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
2174
      {
1707.1.11 by Brian Aker
Move primary_keys to being a vector.
2175
        primary_keys.push_back(row[0]);
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
2176
      }
1 by brian
clean slate
2177
    }
2178
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2179
    drizzle_result_free(&result);
1 by brian
clean slate
2180
  }
2181
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2182
  return(0);
1 by brian
clean slate
2183
}
2184
2185
static int
1441.3.1 by Vijay Samuel
all required updations have been made
2186
create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
2187
              OptionString *engine_stmt, Stats *sptr)
1 by brian
clean slate
2188
{
2189
  char query[HUGE_STRING_LENGTH];
1441.3.1 by Vijay Samuel
all required updations have been made
2190
  Statement *ptr;
2191
  Statement *after_create;
1 by brian
clean slate
2192
  int len;
151 by Brian Aker
Ulonglong to uint64_t
2193
  uint64_t count;
1 by brian
clean slate
2194
  struct timeval start_time, end_time;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2195
1 by brian
clean slate
2196
2197
  gettimeofday(&start_time, NULL);
2198
2199
  len= snprintf(query, HUGE_STRING_LENGTH, "CREATE SCHEMA `%s`", db);
2200
2201
  if (verbose >= 2)
2202
    printf("Loading Pre-data\n");
2203
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2204
  if (run_query(con, NULL, query, len))
1 by brian
clean slate
2205
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2206
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2207
            drizzle_con_error(con));
1 by brian
clean slate
2208
    exit(1);
2209
  }
2210
  else
2211
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2212
    sptr->setCreateCount(sptr->getCreateCount()+1);
1 by brian
clean slate
2213
  }
2214
2215
  if (opt_only_print)
2216
  {
2217
    printf("use %s;\n", db);
2218
  }
2219
  else
2220
  {
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2221
    drizzle_result_st result;
2222
    drizzle_return_t ret;
2223
1 by brian
clean slate
2224
    if (verbose >= 3)
2225
      printf("%s;\n", query);
2226
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2227
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
2228
        ret != DRIZZLE_RETURN_OK)
1 by brian
clean slate
2229
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2230
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2231
              ret == DRIZZLE_RETURN_ERROR_CODE ?
2232
              drizzle_result_error(&result) : drizzle_con_error(con));
1 by brian
clean slate
2233
      exit(1);
2234
    }
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2235
    drizzle_result_free(&result);
1441.3.1 by Vijay Samuel
all required updations have been made
2236
    sptr->setCreateCount(sptr->getCreateCount()+1);
1 by brian
clean slate
2237
  }
2238
2239
  if (engine_stmt)
2240
  {
2241
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1441.3.1 by Vijay Samuel
all required updations have been made
2242
                  engine_stmt->getString());
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2243
    if (run_query(con, NULL, query, len))
1 by brian
clean slate
2244
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2245
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2246
              drizzle_con_error(con));
1 by brian
clean slate
2247
      exit(1);
2248
    }
1441.3.1 by Vijay Samuel
all required updations have been made
2249
    sptr->setCreateCount(sptr->getCreateCount()+1);
1 by brian
clean slate
2250
  }
2251
2252
  count= 0;
2253
  after_create= stmt;
2254
2255
limit_not_met:
1441.3.1 by Vijay Samuel
all required updations have been made
2256
  for (ptr= after_create; ptr && ptr->getLength(); ptr= ptr->getNext(), count++)
1 by brian
clean slate
2257
  {
2258
    if (auto_generate_sql && ( auto_generate_sql_number == count))
2259
      break;
2260
1441.3.1 by Vijay Samuel
all required updations have been made
2261
    if (engine_stmt && engine_stmt->getOption() && ptr->getType() == CREATE_TABLE_TYPE)
1 by brian
clean slate
2262
    {
2263
      char buffer[HUGE_STRING_LENGTH];
2264
1441.3.1 by Vijay Samuel
all required updations have been made
2265
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->getString(),
2266
               engine_stmt->getOption());
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2267
      if (run_query(con, NULL, buffer, strlen(buffer)))
1 by brian
clean slate
2268
      {
2269
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2270
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1 by brian
clean slate
2271
        if (!opt_ignore_sql_errors)
2272
          exit(1);
2273
      }
1441.3.1 by Vijay Samuel
all required updations have been made
2274
      sptr->setCreateCount(sptr->getCreateCount()+1);
1 by brian
clean slate
2275
    }
2276
    else
2277
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2278
      if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1 by brian
clean slate
2279
      {
2280
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2281
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1 by brian
clean slate
2282
        if (!opt_ignore_sql_errors)
2283
          exit(1);
2284
      }
1441.3.1 by Vijay Samuel
all required updations have been made
2285
      sptr->setCreateCount(sptr->getCreateCount()+1);
1 by brian
clean slate
2286
    }
2287
  }
2288
2289
  if (auto_generate_sql && (auto_generate_sql_number > count ))
2290
  {
2291
    /* Special case for auto create, we don't want to create tables twice */
1441.3.1 by Vijay Samuel
all required updations have been made
2292
    after_create= stmt->getNext();
1 by brian
clean slate
2293
    goto limit_not_met;
2294
  }
2295
2296
  gettimeofday(&end_time, NULL);
2297
1441.3.1 by Vijay Samuel
all required updations have been made
2298
  sptr->setCreateTiming(timedif(end_time, start_time));
1 by brian
clean slate
2299
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2300
  return(0);
1 by brian
clean slate
2301
}
2302
2303
static int
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2304
drop_schema(drizzle_con_st *con, const char *db)
1 by brian
clean slate
2305
{
2306
  char query[HUGE_STRING_LENGTH];
2307
  int len;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2308
1 by brian
clean slate
2309
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
2310
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2311
  if (run_query(con, NULL, query, len))
1 by brian
clean slate
2312
  {
2313
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2314
            internal::my_progname, db, drizzle_con_error(con));
1 by brian
clean slate
2315
    exit(1);
2316
  }
2317
2318
2319
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2320
  return(0);
1 by brian
clean slate
2321
}
2322
2323
static int
1441.3.1 by Vijay Samuel
all required updations have been made
2324
run_statements(drizzle_con_st *con, Statement *stmt)
1 by brian
clean slate
2325
{
1441.3.1 by Vijay Samuel
all required updations have been made
2326
  Statement *ptr;
1 by brian
clean slate
2327
1441.3.1 by Vijay Samuel
all required updations have been made
2328
  for (ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
1 by brian
clean slate
2329
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2330
    if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1 by brian
clean slate
2331
    {
2332
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2333
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1 by brian
clean slate
2334
      exit(1);
2335
    }
2336
  }
2337
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2338
  return(0);
1 by brian
clean slate
2339
}
2340
2341
static int
1441.3.1 by Vijay Samuel
all required updations have been made
2342
run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
1 by brian
clean slate
2343
{
893 by Brian Aker
First pass of stripping uint
2344
  uint32_t y;
1 by brian
clean slate
2345
  unsigned int real_concurrency;
2346
  struct timeval start_time, end_time;
1441.3.1 by Vijay Samuel
all required updations have been made
2347
  OptionString *sql_type;
1 by brian
clean slate
2348
  pthread_t mainthread;            /* Thread descriptor */
2349
  pthread_attr_t attr;          /* Thread attributes */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2350
1 by brian
clean slate
2351
2352
  pthread_attr_init(&attr);
2353
  pthread_attr_setdetachstate(&attr,
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2354
                              PTHREAD_CREATE_DETACHED);
1 by brian
clean slate
2355
2356
  pthread_mutex_lock(&counter_mutex);
2357
  thread_counter= 0;
2358
2359
  pthread_mutex_lock(&sleeper_mutex);
2360
  master_wakeup= 1;
2361
  pthread_mutex_unlock(&sleeper_mutex);
2362
2363
  real_concurrency= 0;
2364
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2365
  for (y= 0, sql_type= query_options;
2366
       y < query_statements_count;
1441.3.1 by Vijay Samuel
all required updations have been made
2367
       y++, sql_type= sql_type->getNext())
1 by brian
clean slate
2368
  {
2369
    unsigned int options_loop= 1;
2370
1441.3.1 by Vijay Samuel
all required updations have been made
2371
    if (sql_type->getOption())
1 by brian
clean slate
2372
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2373
      options_loop= strtol(sql_type->getOption(),
1 by brian
clean slate
2374
                           (char **)NULL, 10);
2375
      options_loop= options_loop ? options_loop : 1;
2376
    }
2377
2378
    while (options_loop--)
1707.1.16 by Brian Aker
Memory cleanup around threads.
2379
    {
2380
      for (uint32_t x= 0; x < concur; x++)
1 by brian
clean slate
2381
      {
1707.1.16 by Brian Aker
Memory cleanup around threads.
2382
        ThreadContext *con;
2383
        con= new ThreadContext;
656.1.45 by Monty Taylor
Added null return checks to mallocs in drizzleslap.
2384
        if (con == NULL)
2385
        {
2386
          fprintf(stderr, "Memory Allocation error in scheduler\n");
2387
          exit(1);
2388
        }
1441.3.1 by Vijay Samuel
all required updations have been made
2389
        con->setStmt(stmts[y]);
2390
        con->setLimit(limit);
1 by brian
clean slate
2391
2392
        real_concurrency++;
2393
        /* now you create the thread */
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2394
        if (pthread_create(&mainthread, &attr, run_task,
1 by brian
clean slate
2395
                           (void *)con) != 0)
2396
        {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2397
          fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
1 by brian
clean slate
2398
          exit(1);
2399
        }
2400
        thread_counter++;
2401
      }
1707.1.16 by Brian Aker
Memory cleanup around threads.
2402
    }
1 by brian
clean slate
2403
  }
2404
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2405
  /*
2406
    The timer_thread belongs to all threads so it too obeys the wakeup
1 by brian
clean slate
2407
    call that run tasks obey.
2408
  */
2409
  if (opt_timer_length)
2410
  {
2411
    pthread_mutex_lock(&timer_alarm_mutex);
163 by Brian Aker
Merge Monty's code.
2412
    timer_alarm= true;
1 by brian
clean slate
2413
    pthread_mutex_unlock(&timer_alarm_mutex);
2414
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2415
    if (pthread_create(&mainthread, &attr, timer_thread,
1 by brian
clean slate
2416
                       (void *)&opt_timer_length) != 0)
2417
    {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2418
      fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
1 by brian
clean slate
2419
      exit(1);
2420
    }
2421
  }
2422
2423
  pthread_mutex_unlock(&counter_mutex);
2424
  pthread_attr_destroy(&attr);
2425
2426
  pthread_mutex_lock(&sleeper_mutex);
2427
  master_wakeup= 0;
2428
  pthread_mutex_unlock(&sleeper_mutex);
2429
  pthread_cond_broadcast(&sleep_threshhold);
2430
2431
  gettimeofday(&start_time, NULL);
2432
2433
  /*
2434
    We loop until we know that all children have cleaned up.
2435
  */
2436
  pthread_mutex_lock(&counter_mutex);
2437
  while (thread_counter)
2438
  {
2439
    struct timespec abstime;
2440
2441
    set_timespec(abstime, 3);
2442
    pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
2443
  }
2444
  pthread_mutex_unlock(&counter_mutex);
2445
2446
  gettimeofday(&end_time, NULL);
2447
2448
1441.3.1 by Vijay Samuel
all required updations have been made
2449
  sptr->setTiming(timedif(end_time, start_time));
2450
  sptr->setUsers(concur);
2451
  sptr->setRealUsers(real_concurrency);
2452
  sptr->setRows(limit);
1 by brian
clean slate
2453
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2454
  return(0);
1 by brian
clean slate
2455
}
2456
2457
2458
pthread_handler_t timer_thread(void *p)
2459
{
893 by Brian Aker
First pass of stripping uint
2460
  uint32_t *timer_length= (uint32_t *)p;
1 by brian
clean slate
2461
  struct timespec abstime;
2462
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2463
2464
  /*
2465
    We lock around the initial call in case were we in a loop. This
1 by brian
clean slate
2466
    also keeps the value properly syncronized across call threads.
2467
  */
2468
  pthread_mutex_lock(&sleeper_mutex);
2469
  while (master_wakeup)
2470
  {
2471
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
2472
  }
2473
  pthread_mutex_unlock(&sleeper_mutex);
2474
2475
  set_timespec(abstime, *timer_length);
2476
2477
  pthread_mutex_lock(&timer_alarm_mutex);
2478
  pthread_cond_timedwait(&timer_alarm_threshold, &timer_alarm_mutex, &abstime);
2479
  pthread_mutex_unlock(&timer_alarm_mutex);
2480
2481
  pthread_mutex_lock(&timer_alarm_mutex);
163 by Brian Aker
Merge Monty's code.
2482
  timer_alarm= false;
1 by brian
clean slate
2483
  pthread_mutex_unlock(&timer_alarm_mutex);
2484
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2485
  return(0);
1 by brian
clean slate
2486
}
2487
2488
pthread_handler_t run_task(void *p)
2489
{
151 by Brian Aker
Ulonglong to uint64_t
2490
  uint64_t counter= 0, queries;
2491
  uint64_t detach_counter;
1 by brian
clean slate
2492
  unsigned int commit_counter;
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2493
  drizzle_con_st con;
2494
  drizzle_result_st result;
2495
  drizzle_row_t row;
1441.3.1 by Vijay Samuel
all required updations have been made
2496
  Statement *ptr;
2497
  ThreadContext *ctx= (ThreadContext *)p;
1 by brian
clean slate
2498
2499
  pthread_mutex_lock(&sleeper_mutex);
2500
  while (master_wakeup)
2501
  {
2502
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
2503
  }
2504
  pthread_mutex_unlock(&sleeper_mutex);
2505
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2506
  slap_connect(&con, true);
1 by brian
clean slate
2507
2508
  if (verbose >= 3)
2509
    printf("connected!\n");
2510
  queries= 0;
2511
2512
  commit_counter= 0;
2513
  if (commit_rate)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2514
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
1 by brian
clean slate
2515
2516
limit_not_met:
1441.3.1 by Vijay Samuel
all required updations have been made
2517
  for (ptr= ctx->getStmt(), detach_counter= 0;
2518
       ptr && ptr->getLength();
2519
       ptr= ptr->getNext(), detach_counter++)
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2520
  {
2521
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2522
    {
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2523
      slap_close(&con);
2524
      slap_connect(&con, true);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2525
    }
2526
2527
    /*
2528
      We have to execute differently based on query type. This should become a function.
2529
    */
1441.3.1 by Vijay Samuel
all required updations have been made
2530
    if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
2531
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2532
    {
2533
      int length;
2534
      unsigned int key_val;
2535
      char buffer[HUGE_STRING_LENGTH];
1 by brian
clean slate
2536
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2537
      /*
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2538
        This should only happen if some sort of new engine was
2539
        implemented that didn't properly handle UPDATEs.
2540
2541
        Just in case someone runs this under an experimental engine we don't
2542
        want a crash so the if() is placed here.
1 by brian
clean slate
2543
      */
1707.1.12 by Brian Aker
Remove global for size around primary keys.
2544
      assert(primary_keys.size());
2545
      if (primary_keys.size())
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2546
      {
1707.1.12 by Brian Aker
Remove global for size around primary keys.
2547
        key_val= (unsigned int)(random() % primary_keys.size());
1707.1.11 by Brian Aker
Move primary_keys to being a vector.
2548
        const char *key;
2549
        key= primary_keys[key_val].c_str();
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2550
2551
        assert(key);
2552
2553
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
1441.3.1 by Vijay Samuel
all required updations have been made
2554
                         (int)ptr->getLength(), ptr->getString(), key);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2555
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2556
        if (run_query(&con, &result, buffer, length))
1 by brian
clean slate
2557
        {
2558
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2559
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
1 by brian
clean slate
2560
          exit(1);
2561
        }
2562
      }
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2563
    }
2564
    else
2565
    {
1441.3.1 by Vijay Samuel
all required updations have been made
2566
      if (run_query(&con, &result, ptr->getString(), ptr->getLength()))
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2567
      {
2568
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2569
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2570
        exit(1);
2571
      }
2572
    }
1 by brian
clean slate
2573
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2574
    if (!opt_only_print)
2575
    {
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2576
      while ((row = drizzle_row_next(&result)))
2577
        counter++;
2578
      drizzle_result_free(&result);
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2579
    }
2580
    queries++;
2581
2582
    if (commit_rate && (++commit_counter == commit_rate))
2583
    {
2584
      commit_counter= 0;
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2585
      run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2586
    }
2587
2588
    /* If the timer is set, and the alarm is not active then end */
2589
    if (opt_timer_length && timer_alarm == false)
2590
      goto end;
2591
2592
    /* If limit has been reached, and we are not in a timer_alarm just end */
1441.3.1 by Vijay Samuel
all required updations have been made
2593
    if (ctx->getLimit() && queries == ctx->getLimit() && timer_alarm == false)
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2594
      goto end;
2595
  }
2596
2597
  if (opt_timer_length && timer_alarm == true)
2598
    goto limit_not_met;
2599
1441.3.1 by Vijay Samuel
all required updations have been made
2600
  if (ctx->getLimit() && queries < ctx->getLimit())
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2601
    goto limit_not_met;
1 by brian
clean slate
2602
2603
2604
end:
2605
  if (commit_rate)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2606
    run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
1 by brian
clean slate
2607
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2608
  slap_close(&con);
1 by brian
clean slate
2609
2610
  pthread_mutex_lock(&counter_mutex);
2611
  thread_counter--;
2612
  pthread_cond_signal(&count_threshhold);
2613
  pthread_mutex_unlock(&counter_mutex);
2614
1707.1.16 by Brian Aker
Memory cleanup around threads.
2615
  delete ctx;
1 by brian
clean slate
2616
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2617
  return(0);
1 by brian
clean slate
2618
}
2619
2620
/*
2621
  Parse records from comma seperated string. : is a reserved character and is used for options
2622
  on variables.
2623
*/
2624
uint
1441.3.1 by Vijay Samuel
all required updations have been made
2625
parse_option(const char *origin, OptionString **stmt, char delm)
1 by brian
clean slate
2626
{
2627
  char *string;
2628
  char *begin_ptr;
2629
  char *end_ptr;
893 by Brian Aker
First pass of stripping uint
2630
  uint32_t length= strlen(origin);
2631
  uint32_t count= 0; /* We know that there is always one */
1 by brian
clean slate
2632
2633
  end_ptr= (char *)origin + length;
2634
1707.1.15 by Brian Aker
New fix in drizzleslap.
2635
  OptionString *tmp;
2636
  *stmt= tmp= new OptionString;
1 by brian
clean slate
2637
2638
  for (begin_ptr= (char *)origin;
2639
       begin_ptr != end_ptr;
1441.3.1 by Vijay Samuel
all required updations have been made
2640
       tmp= tmp->getNext())
1 by brian
clean slate
2641
  {
2642
    char buffer[HUGE_STRING_LENGTH];
2643
    char *buffer_ptr;
2644
212.6.1 by Mats Kindahl
Replacing all bzero() calls with memset() calls and removing the bzero.c file.
2645
    memset(buffer, 0, HUGE_STRING_LENGTH);
1 by brian
clean slate
2646
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2647
    string= strchr(begin_ptr, delm);
1 by brian
clean slate
2648
2649
    if (string)
2650
    {
2651
      memcpy(buffer, begin_ptr, string - begin_ptr);
2652
      begin_ptr= string+1;
2653
    }
2654
    else
2655
    {
779.3.10 by Monty Taylor
Turned on -Wshadow.
2656
      size_t begin_len= strlen(begin_ptr);
2657
      memcpy(buffer, begin_ptr, begin_len);
1 by brian
clean slate
2658
      begin_ptr= end_ptr;
2659
    }
2660
2661
    if ((buffer_ptr= strchr(buffer, ':')))
2662
    {
2663
      /* Set a null so that we can get strlen() correct later on */
2664
      buffer_ptr[0]= 0;
2665
      buffer_ptr++;
2666
2667
      /* Move past the : and the first string */
1707.1.20 by Brian Aker
Remove someof the code around an option saving its option
2668
      tmp->setOption(buffer_ptr);
1 by brian
clean slate
2669
    }
2670
1441.3.1 by Vijay Samuel
all required updations have been made
2671
    tmp->setString(strdup(buffer));
2672
    if (tmp->getString() == NULL)
656.1.51 by Monty Taylor
Fixed strdup return checking in client/
2673
    {
2674
      fprintf(stderr,"Error allocating memory while parsing options\n");
2675
      exit(1);
2676
    }
1 by brian
clean slate
2677
2678
    if (isspace(*begin_ptr))
2679
      begin_ptr++;
2680
2681
    count++;
2682
2683
    if (begin_ptr != end_ptr)
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
2684
    {
1707.1.15 by Brian Aker
New fix in drizzleslap.
2685
      tmp->setNext( new OptionString);
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
2686
    }
2687
    
1 by brian
clean slate
2688
  }
2689
2690
  return count;
2691
}
2692
2693
2694
/*
2695
  Raw parsing interface. If you want the slap specific parser look at
2696
  parse_option.
2697
*/
2698
uint
1441.3.1 by Vijay Samuel
all required updations have been made
2699
parse_delimiter(const char *script, Statement **stmt, char delm)
1 by brian
clean slate
2700
{
2701
  char *retstr;
2702
  char *ptr= (char *)script;
1441.3.1 by Vijay Samuel
all required updations have been made
2703
  Statement **sptr= stmt;
2704
  Statement *tmp;
893 by Brian Aker
First pass of stripping uint
2705
  uint32_t length= strlen(script);
2706
  uint32_t count= 0; /* We know that there is always one */
1 by brian
clean slate
2707
1707.1.9 by Brian Aker
Partial pass through the string in statement.
2708
  for (tmp= *sptr= new Statement;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2709
       (retstr= strchr(ptr, delm));
1707.1.9 by Brian Aker
Partial pass through the string in statement.
2710
       tmp->setNext(new Statement),
1441.3.1 by Vijay Samuel
all required updations have been made
2711
       tmp= tmp->getNext())
1 by brian
clean slate
2712
  {
1014.8.2 by Toru Maesaka
Add memory allocation check and fix SEGV problem caused in statement_cleanup() by using calloc. This is temporary, the query statement list should be migrated to a proper container like std::vector
2713
    if (tmp == NULL)
2714
    {
2715
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2716
      exit(1);
2717
    }
2718
1 by brian
clean slate
2719
    count++;
1707.1.9 by Brian Aker
Partial pass through the string in statement.
2720
    tmp->setString((size_t)(retstr - ptr));
1014.8.2 by Toru Maesaka
Add memory allocation check and fix SEGV problem caused in statement_cleanup() by using calloc. This is temporary, the query statement list should be migrated to a proper container like std::vector
2721
1441.3.1 by Vijay Samuel
all required updations have been made
2722
    if (tmp->getString() == NULL)
656.1.50 by Monty Taylor
More malloc return type checking
2723
    {
2724
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2725
      exit(1);
2726
    }
1014.8.2 by Toru Maesaka
Add memory allocation check and fix SEGV problem caused in statement_cleanup() by using calloc. This is temporary, the query statement list should be migrated to a proper container like std::vector
2727
1441.3.1 by Vijay Samuel
all required updations have been made
2728
    memcpy(tmp->getString(), ptr, tmp->getLength());
1 by brian
clean slate
2729
    ptr+= retstr - ptr + 1;
2730
    if (isspace(*ptr))
2731
      ptr++;
2732
  }
2733
2734
  if (ptr != script+length)
2735
  {
1707.1.9 by Brian Aker
Partial pass through the string in statement.
2736
    tmp->setString((size_t)((script + length) - ptr));
1441.3.1 by Vijay Samuel
all required updations have been made
2737
    if (tmp->getString() == NULL)
656.1.50 by Monty Taylor
More malloc return type checking
2738
    {
2739
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2740
      exit(1);
2741
    }
1441.3.1 by Vijay Samuel
all required updations have been made
2742
    memcpy(tmp->getString(), ptr, tmp->getLength());
1 by brian
clean slate
2743
    count++;
2744
  }
2745
2746
  return count;
2747
}
2748
2749
2750
/*
2751
  Parse comma is different from parse_delimeter in that it parses
2752
  number ranges from a comma seperated string.
2753
  In restrospect, this is a lousy name from this function.
2754
*/
2755
uint
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
2756
parse_comma(const char *string, std::vector <uint32_t> &range)
1 by brian
clean slate
2757
{
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
2758
  unsigned int count= 1,x; /* We know that there is always one */
1 by brian
clean slate
2759
  char *retstr;
2760
  char *ptr= (char *)string;
656.1.20 by Monty Taylor
Removed my_strdup, my_malloc, my_realloc from client/
2761
  unsigned int *nptr;
1 by brian
clean slate
2762
2763
  for (;*ptr; ptr++)
2764
    if (*ptr == ',') count++;
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2765
1 by brian
clean slate
2766
  /* One extra spot for the NULL */
1707.1.13 by Brian Aker
Merge in changes for allocation on concurrency
2767
  range.resize(count +1);
2768
  nptr= &range[0];
1 by brian
clean slate
2769
2770
  ptr= (char *)string;
2771
  x= 0;
2772
  while ((retstr= strchr(ptr,',')))
2773
  {
2774
    nptr[x++]= atoi(ptr);
2775
    ptr+= retstr - ptr + 1;
2776
  }
2777
  nptr[x++]= atoi(ptr);
2778
2779
  return count;
2780
}
2781
2782
void
1441.3.1 by Vijay Samuel
all required updations have been made
2783
print_conclusions(Conclusions *con)
1 by brian
clean slate
2784
{
2785
  printf("Benchmark\n");
1441.3.1 by Vijay Samuel
all required updations have been made
2786
  if (con->getEngine())
2787
    printf("\tRunning for engine %s\n", con->getEngine());
1531.2.4 by Vijay Samuel
Updated Slap
2788
  if (!opt_label.empty() || !opt_auto_generate_sql_type.empty())
1 by brian
clean slate
2789
  {
1531.2.1 by Vijay Samuel
Slap refactored
2790
    const char *ptr= opt_auto_generate_sql_type.c_str() ? opt_auto_generate_sql_type.c_str() : "query";
1531.2.4 by Vijay Samuel
Updated Slap
2791
    printf("\tLoad: %s\n", !opt_label.empty() ? opt_label.c_str() : ptr);
1 by brian
clean slate
2792
  }
2793
  printf("\tAverage Time took to generate schema and initial data: %ld.%03ld seconds\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2794
         con->getCreateAvgTiming() / 1000, con->getCreateAvgTiming() % 1000);
1 by brian
clean slate
2795
  printf("\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2796
         con->getAvgTiming() / 1000, con->getAvgTiming() % 1000);
1 by brian
clean slate
2797
  printf("\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2798
         con->getMinTiming() / 1000, con->getMinTiming() % 1000);
1 by brian
clean slate
2799
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2800
         con->getMaxTiming() / 1000, con->getMaxTiming() % 1000);
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2801
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2802
         con->getSumOfTime() / 1000, con->getSumOfTime() % 1000);
2803
  printf("\tStandard Deviation: %ld.%03ld\n", con->getStdDev() / 1000, con->getStdDev() % 1000);
2804
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->getCreateCount());
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2805
  printf("\tNumber of clients running queries: %u/%u\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2806
         con->getUsers(), con->getRealUsers());
1 by brian
clean slate
2807
  printf("\tNumber of times test was run: %u\n", iterations);
1441.3.1 by Vijay Samuel
all required updations have been made
2808
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->getAvgRows());
1 by brian
clean slate
2809
  printf("\n");
2810
}
2811
2812
void
1441.3.1 by Vijay Samuel
all required updations have been made
2813
print_conclusions_csv(Conclusions *con)
1 by brian
clean slate
2814
{
2815
  unsigned int x;
2816
  char buffer[HUGE_STRING_LENGTH];
2817
  char label_buffer[HUGE_STRING_LENGTH];
2818
  size_t string_len;
1531.2.7 by Vijay Samuel
updated slap
2819
  const char *temp_label= opt_label.c_str();
1 by brian
clean slate
2820
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
2821
  memset(label_buffer, 0, sizeof(label_buffer));
1 by brian
clean slate
2822
1531.2.4 by Vijay Samuel
Updated Slap
2823
  if (!opt_label.empty())
1 by brian
clean slate
2824
  {
1531.2.1 by Vijay Samuel
Slap refactored
2825
    string_len= opt_label.length();
1 by brian
clean slate
2826
2827
    for (x= 0; x < string_len; x++)
2828
    {
1531.2.7 by Vijay Samuel
updated slap
2829
      if (temp_label[x] == ',')
1 by brian
clean slate
2830
        label_buffer[x]= '-';
2831
      else
1531.2.7 by Vijay Samuel
updated slap
2832
        label_buffer[x]= temp_label[x] ;
1 by brian
clean slate
2833
    }
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2834
  }
1531.2.4 by Vijay Samuel
Updated Slap
2835
  else if (!opt_auto_generate_sql_type.empty())
1 by brian
clean slate
2836
  {
1531.2.1 by Vijay Samuel
Slap refactored
2837
    string_len= opt_auto_generate_sql_type.length();
1 by brian
clean slate
2838
2839
    for (x= 0; x < string_len; x++)
2840
    {
2841
      if (opt_auto_generate_sql_type[x] == ',')
2842
        label_buffer[x]= '-';
2843
      else
2844
        label_buffer[x]= opt_auto_generate_sql_type[x] ;
2845
    }
2846
  }
2847
  else
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
2848
  {
1 by brian
clean slate
2849
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
2850
  }
1 by brian
clean slate
2851
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2852
  snprintf(buffer, HUGE_STRING_LENGTH,
398.1.8 by Monty Taylor
Enabled -Wlong-long.
2853
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2854
           "%u,%u,%u,%"PRIu64"\n",
1441.3.1 by Vijay Samuel
all required updations have been made
2855
           con->getEngine() ? con->getEngine() : "", /* Storage engine we ran against */
1 by brian
clean slate
2856
           label_buffer, /* Load type */
1441.3.1 by Vijay Samuel
all required updations have been made
2857
           con->getAvgTiming() / 1000, con->getAvgTiming() % 1000, /* Time to load */
2858
           con->getMinTiming() / 1000, con->getMinTiming() % 1000, /* Min time */
2859
           con->getMaxTiming() / 1000, con->getMaxTiming() % 1000, /* Max time */
2860
           con->getSumOfTime() / 1000, con->getSumOfTime() % 1000, /* Total time */
2861
           con->getStdDev() / 1000, con->getStdDev() % 1000, /* Standard Deviation */
1 by brian
clean slate
2862
           iterations, /* Iterations */
1441.3.1 by Vijay Samuel
all required updations have been made
2863
           con->getUsers(), /* Children used max_timing */
2864
           con->getRealUsers(), /* Children used max_timing */
2865
           con->getAvgRows()  /* Queries run */
381 by Monty Taylor
Reformatted slap and test.
2866
           );
1711.1.20 by Monty Taylor
Fixed warning where return value of write() was not being checked.
2867
  size_t buff_len= strlen(buffer);
2868
  ssize_t write_ret= write(csv_file, (unsigned char*) buffer, buff_len);
2869
  if (write_ret != (ssize_t)buff_len)
2870
  {
2871
    fprintf(stderr, _("Unable to fully write %"PRIu64" bytes. "
2872
                      "Could only write %"PRId64"."), (uint64_t)write_ret,
2873
                      (int64_t)buff_len);
2874
    exit(-1);
2875
  }
1 by brian
clean slate
2876
}
2877
2878
void
1441.3.1 by Vijay Samuel
all required updations have been made
2879
generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
1 by brian
clean slate
2880
{
1441.3.1 by Vijay Samuel
all required updations have been made
2881
  Stats *ptr;
1 by brian
clean slate
2882
  unsigned int x;
2883
1441.3.1 by Vijay Samuel
all required updations have been made
2884
  con->setMinTiming(sptr->getTiming());
2885
  con->setMaxTiming(sptr->getTiming());
2886
  con->setMinRows(sptr->getRows());
2887
  con->setMaxRows(sptr->getRows());
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2888
1 by brian
clean slate
2889
  /* At the moment we assume uniform */
1441.3.1 by Vijay Samuel
all required updations have been made
2890
  con->setUsers(sptr->getUsers());
2891
  con->setRealUsers(sptr->getRealUsers());
2892
  con->setAvgRows(sptr->getRows());
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2893
1 by brian
clean slate
2894
  /* With no next, we know it is the last element that was malloced */
2895
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2896
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2897
    con->setAvgTiming(ptr->getTiming()+con->getAvgTiming());
1 by brian
clean slate
2898
1441.3.1 by Vijay Samuel
all required updations have been made
2899
    if (ptr->getTiming() > con->getMaxTiming())
2900
      con->setMaxTiming(ptr->getTiming());
2901
    if (ptr->getTiming() < con->getMinTiming())
2902
      con->setMinTiming(ptr->getTiming());
1 by brian
clean slate
2903
  }
1441.3.1 by Vijay Samuel
all required updations have been made
2904
  con->setSumOfTime(con->getAvgTiming());
2905
  con->setAvgTiming(con->getAvgTiming()/iterations);
1 by brian
clean slate
2906
1441.3.1 by Vijay Samuel
all required updations have been made
2907
  if (eng && eng->getString())
2908
    con->setEngine(eng->getString());
1 by brian
clean slate
2909
  else
1441.3.1 by Vijay Samuel
all required updations have been made
2910
    con->setEngine(NULL);
1 by brian
clean slate
2911
2912
  standard_deviation(con, sptr);
2913
2914
  /* Now we do the create time operations */
1441.3.1 by Vijay Samuel
all required updations have been made
2915
  con->setCreateMinTiming(sptr->getCreateTiming());
2916
  con->setCreateMaxTiming(sptr->getCreateTiming());
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2917
1 by brian
clean slate
2918
  /* At the moment we assume uniform */
1441.3.1 by Vijay Samuel
all required updations have been made
2919
  con->setCreateCount(sptr->getCreateCount());
377.1.5 by Brian Aker
Merge from Monty, cleanup in tabs during merg.
2920
1 by brian
clean slate
2921
  /* With no next, we know it is the last element that was malloced */
2922
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2923
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2924
    con->setCreateAvgTiming(ptr->getCreateTiming()+con->getCreateAvgTiming());
1 by brian
clean slate
2925
1441.3.1 by Vijay Samuel
all required updations have been made
2926
    if (ptr->getCreateTiming() > con->getCreateMaxTiming())
2927
      con->setCreateMaxTiming(ptr->getCreateTiming());
2928
    if (ptr->getCreateTiming() < con->getCreateMinTiming())
2929
      con->setCreateMinTiming(ptr->getCreateTiming());
1 by brian
clean slate
2930
  }
1441.3.1 by Vijay Samuel
all required updations have been made
2931
  con->setCreateAvgTiming(con->getCreateAvgTiming()/iterations);
1 by brian
clean slate
2932
}
2933
2934
void
1441.3.1 by Vijay Samuel
all required updations have been made
2935
option_cleanup(OptionString *stmt)
1 by brian
clean slate
2936
{
1441.3.1 by Vijay Samuel
all required updations have been made
2937
  OptionString *ptr, *nptr;
1707.1.16 by Brian Aker
Memory cleanup around threads.
2938
  if (not stmt)
1 by brian
clean slate
2939
    return;
2940
2941
  for (ptr= stmt; ptr; ptr= nptr)
2942
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2943
    nptr= ptr->getNext();
1707.1.15 by Brian Aker
New fix in drizzleslap.
2944
    delete ptr;
1 by brian
clean slate
2945
  }
2946
}
2947
2948
void
1441.3.1 by Vijay Samuel
all required updations have been made
2949
statement_cleanup(Statement *stmt)
1 by brian
clean slate
2950
{
1441.3.1 by Vijay Samuel
all required updations have been made
2951
  Statement *ptr, *nptr;
1 by brian
clean slate
2952
  if (!stmt)
2953
    return;
2954
2955
  for (ptr= stmt; ptr; ptr= nptr)
2956
  {
1441.3.1 by Vijay Samuel
all required updations have been made
2957
    nptr= ptr->getNext();
1707.1.8 by Brian Aker
Minor cleanups in the slap code.
2958
    delete ptr;
1 by brian
clean slate
2959
  }
2960
}
2961
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2962
void
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2963
slap_close(drizzle_con_st *con)
1 by brian
clean slate
2964
{
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2965
  if (opt_only_print)
1 by brian
clean slate
2966
    return;
2967
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2968
  drizzle_free(drizzle_con_drizzle(con));
1 by brian
clean slate
2969
}
2970
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2971
void
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2972
slap_connect(drizzle_con_st *con, bool connect_to_schema)
1 by brian
clean slate
2973
{
2974
  /* Connect to server */
288 by Brian Aker
ulong cleanp in client apps
2975
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
1707.1.18 by Brian Aker
Style cleanups.
2976
  int connect_error= 1;
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2977
  drizzle_return_t ret;
2978
  drizzle_st *drizzle;
1 by brian
clean slate
2979
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
2980
  if (opt_only_print)
1 by brian
clean slate
2981
    return;
2982
2983
  if (opt_delayed_start)
685.3.1 by Toru Maesaka
Removed my_mkdir() and my_sleep()
2984
    usleep(random()%opt_delayed_start);
1 by brian
clean slate
2985
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2986
  if ((drizzle= drizzle_create(NULL)) == NULL ||
1745.2.1 by LinuxJedi
Remove the --mysql option and convert the --protocol option to do something similar.
2987
      drizzle_con_add_tcp(drizzle, con, host.c_str(), opt_drizzle_port,
2988
        user.c_str(),
2989
        opt_password.c_str(),
2990
        connect_to_schema ? create_schema_string.c_str() : NULL,
2991
        use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2992
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
2993
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2994
    exit(1);
2995
  }
1 by brian
clean slate
2996
1707.1.18 by Brian Aker
Style cleanups.
2997
  for (uint32_t x= 0; x < 10; x++)
1 by brian
clean slate
2998
  {
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
2999
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
1 by brian
clean slate
3000
    {
3001
      /* Connect suceeded */
3002
      connect_error= 0;
3003
      break;
3004
    }
685.3.1 by Toru Maesaka
Removed my_mkdir() and my_sleep()
3005
    usleep(connection_retry_sleep);
1 by brian
clean slate
3006
  }
3007
  if (connect_error)
3008
  {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
3009
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
928.1.7 by Eric Day
Tools mostly converted, still fixing bugs from test suite.
3010
            ret, drizzle_con_error(con));
1 by brian
clean slate
3011
    exit(1);
3012
  }
3013
3014
  return;
3015
}
3016
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
3017
void
1441.3.1 by Vijay Samuel
all required updations have been made
3018
standard_deviation (Conclusions *con, Stats *sptr)
1 by brian
clean slate
3019
{
3020
  unsigned int x;
3021
  long int sum_of_squares;
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
3022
  double the_catch;
1441.3.1 by Vijay Samuel
all required updations have been made
3023
  Stats *ptr;
1 by brian
clean slate
3024
3025
  if (iterations == 1 || iterations == 0)
3026
  {
1441.3.1 by Vijay Samuel
all required updations have been made
3027
    con->setStdDev(0);
1 by brian
clean slate
3028
    return;
3029
  }
3030
3031
  for (ptr= sptr, x= 0, sum_of_squares= 0; x < iterations; ptr++, x++)
3032
  {
3033
    long int deviation;
3034
1441.3.1 by Vijay Samuel
all required updations have been made
3035
    deviation= ptr->getTiming() - con->getAvgTiming();
1 by brian
clean slate
3036
    sum_of_squares+= deviation*deviation;
3037
  }
3038
373.1.9 by Monty Taylor
Added back mysqlslap as drizzleslap. Also made it C++ and removed DYNAMIC_STRING.
3039
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
1441.3.1 by Vijay Samuel
all required updations have been made
3040
  con->setStdDev((long int)the_catch);
1 by brian
clean slate
3041
}