~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqlslap.c

MergedĀ fromĀ Patrick.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2005 MySQL AB
 
1
/* Copyright (C) 2008 Drizzle Open Source Development Team
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
19
19
 
20
20
 
21
21
/*
22
 
  MySQL Slap
 
22
  Drizzle Slap
23
23
 
24
24
  A simple program designed to work as if multiple clients querying the database,
25
25
  then reporting the timing of each stage.
26
26
 
27
 
  MySQL slap runs three stages:
 
27
  Drizzle slap runs three stages:
28
28
  1) Create schema,table, and optionally any SP or data you want to beign
29
29
     the test with. (single client)
30
30
  2) Load test (many clients)
32
32
 
33
33
  Examples:
34
34
 
35
 
  Supply your own create and query SQL statements, with 50 clients 
 
35
  Supply your own create and query SQL statements, with 50 clients
36
36
  querying (200 selects for each):
37
37
 
38
 
    mysqlslap --delimiter=";" \
 
38
    drizzleslap --delimiter=";" \
39
39
              --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
40
40
              --query="SELECT * FROM A" --concurrency=50 --iterations=200
41
41
 
44
44
  don't create the table or insert the data (using the previous test's
45
45
  schema and data):
46
46
 
47
 
    mysqlslap --concurrency=5 --iterations=20 \
 
47
    drizzleslap --concurrency=5 --iterations=20 \
48
48
              --number-int-cols=2 --number-char-cols=3 \
49
49
              --auto-generate-sql
50
50
 
51
51
  Tell the program to load the create, insert and query SQL statements from
52
52
  the specified files, where the create.sql file has multiple table creation
53
53
  statements delimited by ';' and multiple insert statements delimited by ';'.
54
 
  The --query file will have multiple queries delimited by ';', run all the 
 
54
  The --query file will have multiple queries delimited by ';', run all the
55
55
  load statements, and then run all the queries in the query file
56
56
  with five clients (five times each):
57
57
 
58
 
    mysqlslap --concurrency=5 \
 
58
    drizzleslap --concurrency=5 \
59
59
              --iterations=5 --query=query.sql --create=create.sql \
60
60
              --delimiter=";"
61
61
 
84
84
#include <sys/wait.h>
85
85
#include <ctype.h>
86
86
 
87
 
#ifdef HAVE_SMEM 
 
87
#ifdef HAVE_SMEM
88
88
static char *shared_memory_base_name=0;
89
89
#endif
90
90
 
113
113
            *default_engine= NULL,
114
114
            *pre_system= NULL,
115
115
            *post_system= NULL,
116
 
            *opt_mysql_unix_port= NULL;
 
116
            *opt_drizzle_unix_port= NULL;
117
117
 
118
118
const char *delimiter= "\n";
119
119
 
153
153
static unsigned int num_blob_cols= 0;
154
154
static unsigned int num_blob_cols_size;
155
155
static unsigned int num_blob_cols_size_min;
156
 
static unsigned int num_int_cols_index= 0; 
 
156
static unsigned int num_int_cols_index= 0;
157
157
static unsigned int num_char_cols_index= 0;
158
158
static unsigned int iterations;
159
159
static uint my_end_arg= 0;
173
173
const char *opt_csv_str;
174
174
File csv_file;
175
175
 
176
 
static uint opt_protocol= MYSQL_PROTOCOL_TCP;
 
176
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
177
177
 
178
178
static int get_options(int *argc,char ***argv);
179
 
static uint opt_mysql_port= 0;
 
179
static uint opt_drizzle_port= 0;
180
180
 
181
181
static const char *load_default_groups[]= { "mysqlslap","client",0 };
182
182
 
253
253
};
254
254
 
255
255
static option_string *engine_options= NULL;
256
 
static option_string *query_options= NULL; 
257
 
static statement *pre_statements= NULL; 
258
 
static statement *post_statements= NULL; 
 
256
static option_string *query_options= NULL;
 
257
static statement *pre_statements= NULL;
 
258
static statement *post_statements= NULL;
259
259
static statement *create_statements= NULL;
260
260
 
261
261
static statement **query_statements= NULL;
269
269
uint parse_comma(const char *string, uint **range);
270
270
uint parse_delimiter(const char *script, statement **stmt, char delm);
271
271
uint parse_option(const char *origin, option_string **stmt, char delm);
272
 
static int drop_schema(MYSQL *mysql, const char *db);
 
272
static int drop_schema(DRIZZLE *drizzle, const char *db);
273
273
uint get_random_string(char *buf, size_t size);
274
274
static statement *build_table_string(void);
275
275
static statement *build_insert_string(void);
276
276
static statement *build_update_string(void);
277
277
static statement * build_select_string(bool key);
278
 
static int generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt);
 
278
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
279
279
static int drop_primary_key_list(void);
280
 
static int create_schema(MYSQL *mysql, const char *db, statement *stmt, 
 
280
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
281
281
                         option_string *engine_stmt, stats *sptr);
282
 
static int run_scheduler(stats *sptr, statement **stmts, uint concur, 
 
282
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
283
283
                         uint64_t limit);
284
284
pthread_handler_t run_task(void *p);
285
285
pthread_handler_t timer_thread(void *p);
286
286
void statement_cleanup(statement *stmt);
287
287
void option_cleanup(option_string *stmt);
288
 
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr);
289
 
static int run_statements(MYSQL *mysql, statement *stmt);
290
 
void slap_connect(MYSQL *mysql, bool connect_to_schema);
291
 
void slap_close(MYSQL *mysql);
292
 
static int run_query(MYSQL *mysql, const char *query, int len);
 
288
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
 
289
static int run_statements(DRIZZLE *drizzle, statement *stmt);
 
290
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
 
291
void slap_close(DRIZZLE *drizzle);
 
292
static int run_query(DRIZZLE *drizzle, const char *query, int len);
293
293
void standard_deviation (conclusions *con, stats *sptr);
294
294
 
295
295
static const char ALPHANUMERICS[]=
301
301
static long int timedif(struct timeval a, struct timeval b)
302
302
{
303
303
    register int us, s;
304
 
 
 
304
 
305
305
    us = a.tv_usec - b.tv_usec;
306
306
    us /= 1000;
307
307
    s = a.tv_sec - b.tv_sec;
311
311
 
312
312
int main(int argc, char **argv)
313
313
{
314
 
  MYSQL mysql;
 
314
  DRIZZLE drizzle;
315
315
  option_string *eptr;
316
316
  unsigned int x;
317
317
 
319
319
 
320
320
  MY_INIT(argv[0]);
321
321
 
322
 
  if (!(mysql_thread_safe()))
 
322
  if (!(drizzle_thread_safe()))
323
323
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
324
324
 
325
325
  load_defaults("my",load_default_groups,&argc,&argv);
350
350
    exit(1);
351
351
  }
352
352
 
353
 
  slap_connect(&mysql, false);
 
353
  slap_connect(&drizzle, false);
354
354
 
355
355
  VOID(pthread_mutex_init(&counter_mutex, NULL));
356
356
  VOID(pthread_cond_init(&count_threshhold, NULL));
374
374
    if (*concurrency)
375
375
    {
376
376
      for (current= concurrency; current && *current; current++)
377
 
        concurrency_loop(&mysql, *current, eptr);
 
377
        concurrency_loop(&drizzle, *current, eptr);
378
378
    }
379
379
    else
380
380
    {
381
381
      uint infinite= 1;
382
382
      do {
383
 
        concurrency_loop(&mysql, infinite, eptr);
 
383
        concurrency_loop(&drizzle, infinite, eptr);
384
384
      }
385
385
      while (infinite++);
386
386
    }
387
387
 
388
388
    if (!opt_preserve)
389
 
      drop_schema(&mysql, create_schema_string);
 
389
      drop_schema(&drizzle, create_schema_string);
390
390
 
391
391
  } while (eptr ? (eptr= eptr->next) : 0);
392
 
  
 
392
 
393
393
  if (opt_burnin)
394
394
    goto burnin;
395
395
 
400
400
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
401
401
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
402
402
 
403
 
  slap_close(&mysql);
 
403
  slap_close(&drizzle);
404
404
 
405
405
  /* now free all the strings we created */
406
406
  if (opt_password)
427
427
  return 0;
428
428
}
429
429
 
430
 
void concurrency_loop(MYSQL *mysql, uint current, option_string *eptr)
 
430
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr)
431
431
{
432
432
  unsigned int x;
433
433
  stats *head_sptr;
435
435
  conclusions conclusion;
436
436
  unsigned long long client_limit;
437
437
 
438
 
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations, 
 
438
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
439
439
                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
440
440
 
441
441
  bzero(&conclusion, sizeof(conclusions));
455
455
      data in the table.
456
456
    */
457
457
    if (opt_preserve == false)
458
 
      drop_schema(mysql, create_schema_string);
 
458
      drop_schema(drizzle, create_schema_string);
459
459
 
460
460
    /* First we create */
461
461
    if (create_statements)
462
 
      create_schema(mysql, create_schema_string, create_statements, eptr, sptr);
 
462
      create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
463
463
 
464
464
    /*
465
465
      If we generated GUID we need to build a list of them from creation that
468
468
    if (verbose >= 2)
469
469
      printf("Generating primary key list\n");
470
470
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
471
 
      generate_primary_key_list(mysql, eptr);
 
471
      generate_primary_key_list(drizzle, eptr);
472
472
 
473
473
    if (commit_rate)
474
 
      run_query(mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
474
      run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
475
475
 
476
476
    if (pre_system)
477
477
      system(pre_system);
478
478
 
479
 
    /* 
480
 
      Pre statements are always run after all other logic so they can 
481
 
      correct/adjust any item that they want. 
 
479
    /*
 
480
      Pre statements are always run after all other logic so they can
 
481
      correct/adjust any item that they want.
482
482
    */
483
483
    if (pre_statements)
484
 
      run_statements(mysql, pre_statements);
 
484
      run_statements(drizzle, pre_statements);
485
485
 
486
 
    run_scheduler(sptr, query_statements, current, client_limit); 
487
 
    
 
486
    run_scheduler(sptr, query_statements, current, client_limit);
 
487
   
488
488
    if (post_statements)
489
 
      run_statements(mysql, post_statements);
 
489
      run_statements(drizzle, post_statements);
490
490
 
491
491
    if (post_system)
492
492
      system(post_system);
517
517
    0, 0, 0, 0, 0, 0},
518
518
  {"auto-generate-sql-select-columns", OPT_SLAP_AUTO_GENERATE_SELECT_COLUMNS,
519
519
    "Provide a string to use for the select fields used in auto tests.",
520
 
    (char**) &auto_generate_selected_columns_opt, 
 
520
    (char**) &auto_generate_selected_columns_opt,
521
521
    (char**) &auto_generate_selected_columns_opt,
522
522
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
523
523
  {"auto-generate-sql", 'a',
526
526
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
527
527
  {"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
528
528
    "Add an AUTO_INCREMENT column to auto-generated tables.",
529
 
    (char**) &auto_generate_sql_autoincrement, 
 
529
    (char**) &auto_generate_sql_autoincrement,
530
530
    (char**) &auto_generate_sql_autoincrement,
531
531
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
532
532
  {"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
535
535
    0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
536
536
  {"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
537
537
    "Add GUID based primary keys to auto-generated tables.",
538
 
    (char**) &auto_generate_sql_guid_primary, 
 
538
    (char**) &auto_generate_sql_guid_primary,
539
539
    (char**) &auto_generate_sql_guid_primary,
540
540
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
541
541
  {"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
542
542
    "Specify test load type: mixed, update, write, key, or read; default is mixed.",
543
543
    (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
544
544
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
545
 
  {"auto-generate-sql-secondary-indexes", 
546
 
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES, 
 
545
  {"auto-generate-sql-secondary-indexes",
 
546
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
547
547
    "Number of secondary indexes to add to auto-generated tables.",
548
 
    (char**) &auto_generate_sql_secondary_indexes, 
 
548
    (char**) &auto_generate_sql_secondary_indexes,
549
549
    (char**) &auto_generate_sql_secondary_indexes, 0,
550
550
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
551
 
  {"auto-generate-sql-unique-query-number", 
 
551
  {"auto-generate-sql-unique-query-number",
552
552
    OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
553
553
    "Number of unique queries to generate for automatic tests.",
554
 
    (char**) &auto_generate_sql_unique_query_number, 
 
554
    (char**) &auto_generate_sql_unique_query_number,
555
555
    (char**) &auto_generate_sql_unique_query_number,
556
556
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
557
 
  {"auto-generate-sql-unique-write-number", 
 
557
  {"auto-generate-sql-unique-write-number",
558
558
    OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
559
559
    "Number of unique queries to generate for auto-generate-sql-write-number.",
560
 
    (char**) &auto_generate_sql_unique_write_number, 
 
560
    (char**) &auto_generate_sql_unique_write_number,
561
561
    (char**) &auto_generate_sql_unique_write_number,
562
562
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
563
563
  {"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
567
567
  {"burnin", OPT_SLAP_BURNIN, "Run full test case in infinite loop.",
568
568
    (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
569
569
    0, 0, 0},
570
 
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS, 
 
570
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS,
571
571
    "Ignore SQL erros in query run.",
572
 
    (char**) &opt_ignore_sql_errors, 
573
 
    (char**) &opt_ignore_sql_errors, 
 
572
    (char**) &opt_ignore_sql_errors,
 
573
    (char**) &opt_ignore_sql_errors,
574
574
    0, GET_BOOL, NO_ARG, 0, 0, 0,
575
575
    0, 0, 0},
576
576
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
586
586
    (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
587
587
    0, 0, 0, 0, 0, 0},
588
588
  {"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
589
 
    (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR, 
 
589
    (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
590
590
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
591
591
  {"csv", OPT_SLAP_CSV,
592
 
        "Generate CSV output to named file or to stdout if no file is named.",
593
 
    (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR, 
 
592
  "Generate CSV output to named file or to stdout if no file is named.",
 
593
    (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
594
594
    OPT_ARG, 0, 0, 0, 0, 0, 0},
595
595
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
596
596
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
597
597
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
598
598
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
599
599
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
600
 
  {"delayed-start", OPT_SLAP_DELAYED_START, 
 
600
  {"delayed-start", OPT_SLAP_DELAYED_START,
601
601
    "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
602
 
    (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT, 
 
602
    (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
603
603
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
604
604
  {"delimiter", 'F',
605
605
    "Delimiter to use in SQL statements supplied in file or command line.",
607
607
    0, 0, 0, 0, 0, 0},
608
608
  {"detach", OPT_SLAP_DETACH,
609
609
    "Detach (close and reopen) connections after X number of requests.",
610
 
    (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG, 
 
610
    (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
611
611
    0, 0, 0, 0, 0, 0},
612
612
  {"engine", 'e', "Storage engine to use for creating the table.",
613
613
    (char**) &default_engine, (char**) &default_engine, 0,
619
619
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
620
620
    (char**) &opt_label, (char**) &opt_label, 0,
621
621
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
622
 
  {"number-blob-cols", OPT_SLAP_BLOB_COL, 
 
622
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
623
623
    "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. ",
624
624
    (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
625
625
    0, 0, 0, 0, 0, 0},
626
 
  {"number-char-cols", 'x', 
 
626
  {"number-char-cols", 'x',
627
627
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
628
628
    (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
629
629
    0, 0, 0, 0, 0, 0},
630
 
  {"number-int-cols", 'y', 
 
630
  {"number-int-cols", 'y',
631
631
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
632
 
    (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG, 
 
632
    (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
633
633
    0, 0, 0, 0, 0, 0},
634
 
  {"number-of-queries", OPT_MYSQL_NUMBER_OF_QUERY, 
 
634
  {"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
635
635
    "Limit each client to this number of queries (this is not exact).",
636
636
    (char**) &num_of_query, (char**) &num_of_query, 0,
637
637
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
638
 
  {"only-print", OPT_MYSQL_ONLY_PRINT,
639
 
    "This causes mysqlslap to not connect to the databases, but instead print "
 
638
  {"only-print", OPT_DRIZZLE_ONLY_PRINT,
 
639
    "This causes drizzleslap to not connect to the databases, but instead print "
640
640
      "out what it would have done instead.",
641
641
    (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
642
642
    0, 0, 0, 0, 0, 0},
643
643
  {"password", 'p',
644
644
    "Password to use when connecting to server. If password is not given it's "
645
645
      "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
646
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_mysql_port,
647
 
    (char**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
 
646
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
 
647
    (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0,
648
648
    0},
649
649
  {"post-query", OPT_SLAP_POST_QUERY,
650
650
    "Query to run or file containing query to execute after tests have completed.",
651
 
    (char**) &user_supplied_post_statements, 
 
651
    (char**) &user_supplied_post_statements,
652
652
    (char**) &user_supplied_post_statements,
653
653
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
654
654
  {"post-system", OPT_SLAP_POST_SYSTEM,
655
655
    "system() string to execute after tests have completed.",
656
 
    (char**) &post_system, 
 
656
    (char**) &post_system,
657
657
    (char**) &post_system,
658
658
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
659
 
  {"pre-query", OPT_SLAP_PRE_QUERY, 
 
659
  {"pre-query", OPT_SLAP_PRE_QUERY,
660
660
    "Query to run or file containing query to execute before running tests.",
661
 
    (char**) &user_supplied_pre_statements, 
 
661
    (char**) &user_supplied_pre_statements,
662
662
    (char**) &user_supplied_pre_statements,
663
663
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
664
 
  {"pre-system", OPT_SLAP_PRE_SYSTEM, 
 
664
  {"pre-system", OPT_SLAP_PRE_SYSTEM,
665
665
    "system() string to execute before running tests.",
666
 
    (char**) &pre_system, 
 
666
    (char**) &pre_system,
667
667
    (char**) &pre_system,
668
668
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
669
 
  {"protocol", OPT_MYSQL_PROTOCOL,
 
669
  {"protocol", OPT_DRIZZLE_PROTOCOL,
670
670
    "The protocol of connection (tcp,socket,pipe,memory).",
671
671
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
672
672
  {"query", 'q', "Query to run or file containing query to run.",
673
673
    (char**) &user_supplied_query, (char**) &user_supplied_query,
674
674
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
675
 
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED, 
 
675
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
676
676
    "Seed for random number generator (srandom(3))",
677
677
    (char**)&opt_set_random_seed,
678
678
    (char**)&opt_set_random_seed,0,
681
681
    (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
682
682
    0, 0, 0, 0, 0, 0},
683
683
  {"socket", 'S', "Socket file to use for connection.",
684
 
    (char**) &opt_mysql_unix_port, (char**) &opt_mysql_unix_port, 0, GET_STR,
 
684
    (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
685
685
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
686
 
  {"timer-length", OPT_SLAP_TIMER_LENGTH, 
687
 
    "Require mysqlslap to run each specific test a certain amount of time in seconds.", 
688
 
    (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT, 
 
686
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
 
687
    "Require drizzleslap to run each specific test a certain amount of time in seconds.",
 
688
    (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
689
689
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
690
690
#ifndef DONT_ALLOW_USER_CHANGE
691
691
  {"user", 'u', "User for login if not current user.", (char**) &user,
693
693
#endif
694
694
  {"verbose", 'v',
695
695
    "More verbose output; you can use this multiple times to get even more "
696
 
      "verbose output.", (char**) &verbose, (char**) &verbose, 0, 
 
696
      "verbose output.", (char**) &verbose, (char**) &verbose, 0,
697
697
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
698
698
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
699
699
    NO_ARG, 0, 0, 0, 0, 0, 0},
713
713
static void usage(void)
714
714
{
715
715
  print_version();
716
 
  puts("Copyright (C) 2005 MySQL AB");
 
716
  puts("Copyright (C) 2005 DRIZZLE AB");
717
717
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
718
718
       \nand you are welcome to modify and redistribute it under the GPL \
719
719
       license\n");
740
740
      char *start= argument;
741
741
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
742
742
      opt_password= my_strdup(argument,MYF(MY_FAE));
743
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
743
      while (*argument) *argument++= 'x';    /* Destroy argument */
744
744
      if (*start)
745
 
        start[1]= 0;                            /* Cut length of argument */
 
745
        start[1]= 0;        /* Cut length of argument */
746
746
      tty_password= 0;
747
747
    }
748
748
    else
753
753
    exit(0);
754
754
    break;
755
755
  case '?':
756
 
  case 'I':                                     /* Info */
 
756
  case 'I':          /* Info */
757
757
    usage();
758
758
    exit(0);
759
759
  }
816
816
      if (count) /* Except for the first pass we add a comma */
817
817
        dynstr_append(&table_string, ",");
818
818
 
819
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count) 
 
819
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
820
820
          > HUGE_STRING_LENGTH)
821
821
      {
822
822
        fprintf(stderr, "Memory Allocation error in create table\n");
834
834
    {
835
835
      if (num_int_cols_index)
836
836
      {
837
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32), INDEX(intcol%d)", 
 
837
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32), INDEX(intcol%d)",
838
838
                     col_count, col_count) > HUGE_STRING_LENGTH)
839
839
        {
840
840
          fprintf(stderr, "Memory Allocation error in create table\n");
843
843
      }
844
844
      else
845
845
      {
846
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32) ", col_count) 
 
846
        if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d INT(32) ", col_count)
847
847
            > HUGE_STRING_LENGTH)
848
848
        {
849
849
          fprintf(stderr, "Memory Allocation error in create table\n");
861
861
    {
862
862
      if (num_char_cols_index)
863
863
      {
864
 
        if (snprintf(buf, HUGE_STRING_LENGTH, 
865
 
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ", 
 
864
        if (snprintf(buf, HUGE_STRING_LENGTH,
 
865
                     "charcol%d VARCHAR(128), INDEX(charcol%d) ",
866
866
                     col_count, col_count) > HUGE_STRING_LENGTH)
867
867
        {
868
868
          fprintf(stderr, "Memory Allocation error in creating table\n");
871
871
      }
872
872
      else
873
873
      {
874
 
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)", 
 
874
        if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d VARCHAR(128)",
875
875
                     col_count) > HUGE_STRING_LENGTH)
876
876
        {
877
877
          fprintf(stderr, "Memory Allocation error in creating table\n");
887
887
  if (num_blob_cols)
888
888
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
889
889
    {
890
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob", 
 
890
      if (snprintf(buf, HUGE_STRING_LENGTH, "blobcol%d blob",
891
891
                   col_count) > HUGE_STRING_LENGTH)
892
892
      {
893
893
        fprintf(stderr, "Memory Allocation error in creating table\n");
900
900
    }
901
901
 
902
902
  dynstr_append(&table_string, ")");
903
 
  ptr= (statement *)my_malloc(sizeof(statement), 
 
903
  ptr= (statement *)my_malloc(sizeof(statement),
904
904
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
905
905
  ptr->string = (char *)my_malloc(table_string.length+1,
906
906
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
933
933
  if (num_int_cols)
934
934
    for (col_count= 1; col_count <= num_int_cols; col_count++)
935
935
    {
936
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count, 
 
936
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d = %ld", col_count,
937
937
                   random()) > HUGE_STRING_LENGTH)
938
938
      {
939
939
        fprintf(stderr, "Memory Allocation error in creating update\n");
951
951
      char rand_buffer[RAND_STRING_SIZE];
952
952
      int buf_len= get_random_string(rand_buffer, RAND_STRING_SIZE);
953
953
 
954
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count, 
955
 
                   buf_len, rand_buffer) 
 
954
      if (snprintf(buf, HUGE_STRING_LENGTH, "charcol%d = '%.*s'", col_count,
 
955
                   buf_len, rand_buffer)
956
956
          > HUGE_STRING_LENGTH)
957
957
      {
958
958
        fprintf(stderr, "Memory Allocation error in creating update\n");
968
968
    dynstr_append(&update_string, " WHERE id = ");
969
969
 
970
970
 
971
 
  ptr= (statement *)my_malloc(sizeof(statement), 
 
971
  ptr= (statement *)my_malloc(sizeof(statement),
972
972
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
973
973
 
974
974
  ptr->string= (char *)my_malloc(update_string.length + 1,
1086
1086
      unsigned int size;
1087
1087
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1088
1088
 
1089
 
      size= difference ? (num_blob_cols_size_min + (random() % difference)) : 
 
1089
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1090
1090
                          num_blob_cols_size;
1091
1091
 
1092
1092
      buf_len= get_random_string(blob_ptr, size);
1150
1150
  {
1151
1151
    for (col_count= 1; col_count <= num_int_cols; col_count++)
1152
1152
    {
1153
 
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count) 
 
1153
      if (snprintf(buf, HUGE_STRING_LENGTH, "intcol%d", col_count)
1154
1154
          > HUGE_STRING_LENGTH)
1155
1155
      {
1156
1156
        fprintf(stderr, "Memory Allocation error in creating select\n");
1192
1192
  }
1193
1193
  dynstr_append(&query_string, " FROM t1");
1194
1194
 
1195
 
  if ((key) && 
 
1195
  if ((key) &&
1196
1196
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1197
1197
    dynstr_append(&query_string, " WHERE id = ");
1198
1198
 
1201
1201
  ptr->string= (char *)my_malloc(query_string.length + 1,
1202
1202
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1203
1203
  ptr->length= query_string.length+1;
1204
 
  if ((key) && 
 
1204
  if ((key) &&
1205
1205
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1206
1206
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1207
1207
  else
1243
1243
      exit(1);
1244
1244
  }
1245
1245
 
1246
 
  if (auto_generate_sql && auto_generate_sql_guid_primary && 
 
1246
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1247
1247
      auto_generate_sql_autoincrement)
1248
1248
  {
1249
1249
      fprintf(stderr,
1265
1265
  if (opt_csv_str)
1266
1266
  {
1267
1267
    opt_silent= true;
1268
 
    
 
1268
   
1269
1269
    if (opt_csv_str[0] == '-')
1270
1270
    {
1271
1271
      csv_file= fileno(stdout);
1344
1344
      printf("Building Create Statements for Auto\n");
1345
1345
 
1346
1346
    create_statements= build_table_string();
1347
 
    /* 
1348
 
      Pre-populate table 
 
1347
    /*
 
1348
      Pre-populate table
1349
1349
    */
1350
 
    for (ptr_statement= create_statements, x= 0; 
1351
 
         x < auto_generate_sql_unique_write_number; 
 
1350
    for (ptr_statement= create_statements, x= 0;
 
1351
         x < auto_generate_sql_unique_write_number;
1352
1352
         x++, ptr_statement= ptr_statement->next)
1353
1353
    {
1354
1354
      ptr_statement->next= build_insert_string();
1360
1360
    if (!opt_auto_generate_sql_type)
1361
1361
      opt_auto_generate_sql_type= "mixed";
1362
1362
 
1363
 
    query_statements_count= 
 
1363
    query_statements_count=
1364
1364
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1365
1365
 
1366
1366
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1375
1375
          printf("Generating SELECT Statements for Auto\n");
1376
1376
 
1377
1377
        query_statements[sql_type_count]= build_select_string(false);
1378
 
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
1379
 
             x < auto_generate_sql_unique_query_number; 
 
1378
        for (ptr_statement= query_statements[sql_type_count], x= 0;
 
1379
             x < auto_generate_sql_unique_query_number;
1380
1380
             x++, ptr_statement= ptr_statement->next)
1381
1381
        {
1382
1382
          ptr_statement->next= build_select_string(false);
1397
1397
        }
1398
1398
 
1399
1399
        query_statements[sql_type_count]= build_select_string(true);
1400
 
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
1401
 
             x < auto_generate_sql_unique_query_number; 
 
1400
        for (ptr_statement= query_statements[sql_type_count], x= 0;
 
1401
             x < auto_generate_sql_unique_query_number;
1402
1402
             x++, ptr_statement= ptr_statement->next)
1403
1403
        {
1404
1404
          ptr_statement->next= build_select_string(true);
1407
1407
      else if (sql_type->string[0] == 'w')
1408
1408
      {
1409
1409
        /*
1410
 
          We generate a number of strings in case the engine is 
 
1410
          We generate a number of strings in case the engine is
1411
1411
          Archive (since strings which were identical one after another
1412
1412
          would be too easily optimized).
1413
1413
        */
1414
1414
        if (verbose >= 2)
1415
1415
          printf("Generating INSERT Statements for Auto\n");
1416
1416
        query_statements[sql_type_count]= build_insert_string();
1417
 
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
1418
 
             x < auto_generate_sql_unique_query_number; 
 
1417
        for (ptr_statement= query_statements[sql_type_count], x= 0;
 
1418
             x < auto_generate_sql_unique_query_number;
1419
1419
             x++, ptr_statement= ptr_statement->next)
1420
1420
        {
1421
1421
          ptr_statement->next= build_insert_string();
1433
1433
        }
1434
1434
 
1435
1435
        query_statements[sql_type_count]= build_update_string();
1436
 
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
1437
 
             x < auto_generate_sql_unique_query_number; 
 
1436
        for (ptr_statement= query_statements[sql_type_count], x= 0;
 
1437
             x < auto_generate_sql_unique_query_number;
1438
1438
             x++, ptr_statement= ptr_statement->next)
1439
1439
        {
1440
1440
          ptr_statement->next= build_update_string();
1445
1445
        int coin= 0;
1446
1446
 
1447
1447
        query_statements[sql_type_count]= build_insert_string();
1448
 
        /* 
 
1448
        /*
1449
1449
          This logic should be extended to do a more mixed load,
1450
1450
          at the moment it results in "every other".
1451
1451
        */
1452
 
        for (ptr_statement= query_statements[sql_type_count], x= 0; 
1453
 
             x < auto_generate_sql_unique_query_number; 
 
1452
        for (ptr_statement= query_statements[sql_type_count], x= 0;
 
1453
             x < auto_generate_sql_unique_query_number;
1454
1454
             x++, ptr_statement= ptr_statement->next)
1455
1455
        {
1456
1456
          if (coin)
1500
1500
    /* Set this up till we fully support options on user generated queries */
1501
1501
    if (user_supplied_query)
1502
1502
    {
1503
 
      query_statements_count= 
 
1503
      query_statements_count=
1504
1504
        parse_option("default", &query_options, ',');
1505
1505
 
1506
1506
      query_statements= (statement **)my_malloc(sizeof(statement *),
1530
1530
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1531
1531
                                        delimiter[0]);
1532
1532
      my_free(tmp_string, MYF(0));
1533
 
    } 
 
1533
    }
1534
1534
    else if (user_supplied_query)
1535
1535
    {
1536
1536
      actual_queries= parse_delimiter(user_supplied_query, &query_statements[0],
1562
1562
      (void)parse_delimiter(tmp_string, &pre_statements,
1563
1563
                            delimiter[0]);
1564
1564
    my_free(tmp_string, MYF(0));
1565
 
  } 
 
1565
  }
1566
1566
  else if (user_supplied_pre_statements)
1567
1567
  {
1568
1568
    (void)parse_delimiter(user_supplied_pre_statements,
1594
1594
      (void)parse_delimiter(tmp_string, &post_statements,
1595
1595
                            delimiter[0]);
1596
1596
    my_free(tmp_string, MYF(0));
1597
 
  } 
 
1597
  }
1598
1598
  else if (user_supplied_post_statements)
1599
1599
  {
1600
1600
    (void)parse_delimiter(user_supplied_post_statements, &post_statements,
1613
1613
}
1614
1614
 
1615
1615
 
1616
 
static int run_query(MYSQL *mysql, const char *query, int len)
 
1616
static int run_query(DRIZZLE *drizzle, const char *query, int len)
1617
1617
{
1618
1618
  if (opt_only_print)
1619
1619
  {
1623
1623
 
1624
1624
  if (verbose >= 3)
1625
1625
    printf("%.*s;\n", len, query);
1626
 
  return mysql_real_query(mysql, query, len);
 
1626
  return drizzle_real_query(drizzle, query, len);
1627
1627
}
1628
1628
 
1629
1629
 
1630
1630
static int
1631
 
generate_primary_key_list(MYSQL *mysql, option_string *engine_stmt)
 
1631
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1632
1632
{
1633
 
  MYSQL_RES *result;
1634
 
  MYSQL_ROW row;
 
1633
  DRIZZLE_RES *result;
 
1634
  DRIZZLE_ROW row;
1635
1635
  unsigned long long counter;
1636
1636
 
1637
1637
 
1638
 
  /* 
1639
 
    Blackhole is a special case, this allows us to test the upper end 
 
1638
  /*
 
1639
    Blackhole is a special case, this allows us to test the upper end
1640
1640
    of the server during load runs.
1641
1641
  */
1642
 
  if (opt_only_print || (engine_stmt && 
 
1642
  if (opt_only_print || (engine_stmt &&
1643
1643
                         strstr(engine_stmt->string, "blackhole")))
1644
1644
  {
1645
1645
    primary_keys_number_of= 1;
1646
 
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
1647
 
                                            primary_keys_number_of), 
 
1646
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
 
1647
                                            primary_keys_number_of),
1648
1648
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1649
1649
    /* Yes, we strdup a const string to simplify the interface */
1650
 
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0)); 
 
1650
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
1651
1651
  }
1652
1652
  else
1653
1653
  {
1654
 
    if (run_query(mysql, "SELECT id from t1", strlen("SELECT id from t1")))
 
1654
    if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1655
1655
    {
1656
1656
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1657
 
              mysql_error(mysql));
 
1657
              drizzle_error(drizzle));
1658
1658
      exit(1);
1659
1659
    }
1660
1660
 
1661
 
    result= mysql_store_result(mysql);
1662
 
    primary_keys_number_of= mysql_num_rows(result);
 
1661
    result= drizzle_store_result(drizzle);
 
1662
    primary_keys_number_of= drizzle_num_rows(result);
1663
1663
 
1664
1664
    /* So why check this? Blackhole :) */
1665
1665
    if (primary_keys_number_of)
1667
1667
      /*
1668
1668
        We create the structure and loop and create the items.
1669
1669
      */
1670
 
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) * 
1671
 
                                              primary_keys_number_of), 
 
1670
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
 
1671
                                              primary_keys_number_of),
1672
1672
                                       MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1673
 
      row= mysql_fetch_row(result);
1674
 
      for (counter= 0; counter < primary_keys_number_of; 
1675
 
           counter++, row= mysql_fetch_row(result))
 
1673
      row= drizzle_fetch_row(result);
 
1674
      for (counter= 0; counter < primary_keys_number_of;
 
1675
           counter++, row= drizzle_fetch_row(result))
1676
1676
        primary_keys[counter]= my_strdup(row[0], MYF(0));
1677
1677
    }
1678
1678
 
1679
 
    mysql_free_result(result);
 
1679
    drizzle_free_result(result);
1680
1680
  }
1681
1681
 
1682
1682
  return(0);
1699
1699
}
1700
1700
 
1701
1701
static int
1702
 
create_schema(MYSQL *mysql, const char *db, statement *stmt, 
 
1702
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
1703
1703
              option_string *engine_stmt, stats *sptr)
1704
1704
{
1705
1705
  char query[HUGE_STRING_LENGTH];
1717
1717
  if (verbose >= 2)
1718
1718
    printf("Loading Pre-data\n");
1719
1719
 
1720
 
  if (run_query(mysql, query, len))
 
1720
  if (run_query(drizzle, query, len))
1721
1721
  {
1722
1722
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1723
 
            mysql_error(mysql));
 
1723
            drizzle_error(drizzle));
1724
1724
    exit(1);
1725
1725
  }
1726
1726
  else
1737
1737
    if (verbose >= 3)
1738
1738
      printf("%s;\n", query);
1739
1739
 
1740
 
    if (mysql_select_db(mysql,  db))
 
1740
    if (drizzle_select_db(drizzle,  db))
1741
1741
    {
1742
1742
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1743
 
              mysql_error(mysql));
 
1743
              drizzle_error(drizzle));
1744
1744
      exit(1);
1745
1745
    }
1746
1746
    sptr->create_count++;
1750
1750
  {
1751
1751
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1752
1752
                  engine_stmt->string);
1753
 
    if (run_query(mysql, query, len))
 
1753
    if (run_query(drizzle, query, len))
1754
1754
    {
1755
1755
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1756
 
              mysql_error(mysql));
 
1756
              drizzle_error(drizzle));
1757
1757
      exit(1);
1758
1758
    }
1759
1759
    sptr->create_count++;
1772
1772
    {
1773
1773
      char buffer[HUGE_STRING_LENGTH];
1774
1774
 
1775
 
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string, 
 
1775
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1776
1776
               engine_stmt->option);
1777
 
      if (run_query(mysql, buffer, strlen(buffer)))
 
1777
      if (run_query(drizzle, buffer, strlen(buffer)))
1778
1778
      {
1779
1779
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1780
 
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
 
1780
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
1781
1781
        if (!opt_ignore_sql_errors)
1782
1782
          exit(1);
1783
1783
      }
1785
1785
    }
1786
1786
    else
1787
1787
    {
1788
 
      if (run_query(mysql, ptr->string, ptr->length))
 
1788
      if (run_query(drizzle, ptr->string, ptr->length))
1789
1789
      {
1790
1790
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1791
 
                my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
 
1791
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
1792
1792
        if (!opt_ignore_sql_errors)
1793
1793
          exit(1);
1794
1794
      }
1811
1811
}
1812
1812
 
1813
1813
static int
1814
 
drop_schema(MYSQL *mysql, const char *db)
 
1814
drop_schema(DRIZZLE *drizzle, const char *db)
1815
1815
{
1816
1816
  char query[HUGE_STRING_LENGTH];
1817
1817
  int len;
1818
1818
 
1819
1819
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1820
1820
 
1821
 
  if (run_query(mysql, query, len))
 
1821
  if (run_query(drizzle, query, len))
1822
1822
  {
1823
1823
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1824
 
            my_progname, db, mysql_error(mysql));
 
1824
            my_progname, db, drizzle_error(drizzle));
1825
1825
    exit(1);
1826
1826
  }
1827
1827
 
1831
1831
}
1832
1832
 
1833
1833
static int
1834
 
run_statements(MYSQL *mysql, statement *stmt) 
 
1834
run_statements(DRIZZLE *drizzle, statement *stmt)
1835
1835
{
1836
1836
  statement *ptr;
1837
 
  MYSQL_RES *result;
 
1837
  DRIZZLE_RES *result;
1838
1838
 
1839
1839
 
1840
1840
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
1841
1841
  {
1842
 
    if (run_query(mysql, ptr->string, ptr->length))
 
1842
    if (run_query(drizzle, ptr->string, ptr->length))
1843
1843
    {
1844
1844
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1845
 
              my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
 
1845
              my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
1846
1846
      exit(1);
1847
1847
    }
1848
1848
    if (!opt_only_print)
1849
1849
    {
1850
 
      if (mysql_field_count(mysql))
 
1850
      if (drizzle_field_count(drizzle))
1851
1851
      {
1852
 
        result= mysql_store_result(mysql);
1853
 
        mysql_free_result(result);
 
1852
        result= drizzle_store_result(drizzle);
 
1853
        drizzle_free_result(result);
1854
1854
      }
1855
1855
    }
1856
1856
  }
1873
1873
 
1874
1874
  pthread_attr_init(&attr);
1875
1875
  pthread_attr_setdetachstate(&attr,
1876
 
                  PTHREAD_CREATE_DETACHED);
 
1876
      PTHREAD_CREATE_DETACHED);
1877
1877
 
1878
1878
  pthread_mutex_lock(&counter_mutex);
1879
1879
  thread_counter= 0;
1884
1884
 
1885
1885
  real_concurrency= 0;
1886
1886
 
1887
 
  for (y= 0, sql_type= query_options; 
1888
 
       y < query_statements_count; 
 
1887
  for (y= 0, sql_type= query_options;
 
1888
       y < query_statements_count;
1889
1889
       y++, sql_type= sql_type->next)
1890
1890
  {
1891
1891
    unsigned int options_loop= 1;
1892
1892
 
1893
1893
    if (sql_type->option)
1894
1894
    {
1895
 
      options_loop= strtol(sql_type->option, 
 
1895
      options_loop= strtol(sql_type->option,
1896
1896
                           (char **)NULL, 10);
1897
1897
      options_loop= options_loop ? options_loop : 1;
1898
1898
    }
1906
1906
 
1907
1907
        real_concurrency++;
1908
1908
        /* now you create the thread */
1909
 
        if (pthread_create(&mainthread, &attr, run_task, 
 
1909
        if (pthread_create(&mainthread, &attr, run_task,
1910
1910
                           (void *)con) != 0)
1911
1911
        {
1912
1912
          fprintf(stderr,"%s: Could not create thread\n", my_progname);
1916
1916
      }
1917
1917
  }
1918
1918
 
1919
 
  /* 
1920
 
    The timer_thread belongs to all threads so it too obeys the wakeup 
 
1919
  /*
 
1920
    The timer_thread belongs to all threads so it too obeys the wakeup
1921
1921
    call that run tasks obey.
1922
1922
  */
1923
1923
  if (opt_timer_length)
1926
1926
    timer_alarm= true;
1927
1927
    pthread_mutex_unlock(&timer_alarm_mutex);
1928
1928
 
1929
 
    if (pthread_create(&mainthread, &attr, timer_thread, 
 
1929
    if (pthread_create(&mainthread, &attr, timer_thread,
1930
1930
                       (void *)&opt_timer_length) != 0)
1931
1931
    {
1932
1932
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
1976
1976
 
1977
1977
 
1978
1978
 
1979
 
  if (mysql_thread_init())
 
1979
  if (drizzle_thread_init())
1980
1980
  {
1981
 
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
1981
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
1982
1982
            my_progname);
1983
1983
    exit(1);
1984
1984
  }
1985
1985
 
1986
 
  /* 
1987
 
    We lock around the initial call in case were we in a loop. This 
 
1986
  /*
 
1987
    We lock around the initial call in case were we in a loop. This
1988
1988
    also keeps the value properly syncronized across call threads.
1989
1989
  */
1990
1990
  pthread_mutex_lock(&sleeper_mutex);
2004
2004
  timer_alarm= false;
2005
2005
  pthread_mutex_unlock(&timer_alarm_mutex);
2006
2006
 
2007
 
  mysql_thread_end();
 
2007
  drizzle_thread_end();
2008
2008
  return(0);
2009
2009
}
2010
2010
 
2013
2013
  uint64_t counter= 0, queries;
2014
2014
  uint64_t detach_counter;
2015
2015
  unsigned int commit_counter;
2016
 
  MYSQL mysql;
2017
 
  MYSQL_RES *result;
2018
 
  MYSQL_ROW row;
 
2016
  DRIZZLE drizzle;
 
2017
  DRIZZLE_RES *result;
 
2018
  DRIZZLE_ROW row;
2019
2019
  statement *ptr;
2020
2020
  thread_context *con= (thread_context *)p;
2021
2021
 
2022
 
  if (mysql_thread_init())
 
2022
  if (drizzle_thread_init())
2023
2023
  {
2024
 
    fprintf(stderr,"%s: mysql_thread_init() failed.\n",
 
2024
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
2025
2025
            my_progname);
2026
2026
    exit(1);
2027
2027
  }
2033
2033
  }
2034
2034
  pthread_mutex_unlock(&sleeper_mutex);
2035
2035
 
2036
 
  slap_connect(&mysql, true);
 
2036
  slap_connect(&drizzle, true);
2037
2037
 
2038
2038
  if (verbose >= 3)
2039
2039
    printf("connected!\n");
2041
2041
 
2042
2042
  commit_counter= 0;
2043
2043
  if (commit_rate)
2044
 
    run_query(&mysql, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
2044
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2045
2045
 
2046
2046
limit_not_met:
2047
 
    for (ptr= con->stmt, detach_counter= 0; 
2048
 
         ptr && ptr->length; 
 
2047
    for (ptr= con->stmt, detach_counter= 0;
 
2048
         ptr && ptr->length;
2049
2049
         ptr= ptr->next, detach_counter++)
2050
2050
    {
2051
2051
      if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2052
2052
      {
2053
 
        slap_close(&mysql);
2054
 
        slap_connect(&mysql, true);
 
2053
        slap_close(&drizzle);
 
2054
        slap_connect(&drizzle, true);
2055
2055
      }
2056
2056
 
2057
 
      /* 
 
2057
      /*
2058
2058
        We have to execute differently based on query type. This should become a function.
2059
2059
      */
2060
2060
      if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
2065
2065
        char *key;
2066
2066
        char buffer[HUGE_STRING_LENGTH];
2067
2067
 
2068
 
        /* 
 
2068
        /*
2069
2069
          This should only happen if some sort of new engine was
2070
2070
          implemented that didn't properly handle UPDATEs.
2071
2071
 
2080
2080
 
2081
2081
          assert(key);
2082
2082
 
2083
 
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'", 
 
2083
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2084
2084
                           (int)ptr->length, ptr->string, key);
2085
2085
 
2086
 
          if (run_query(&mysql, buffer, length))
 
2086
          if (run_query(&drizzle, buffer, length))
2087
2087
          {
2088
2088
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2089
 
                    my_progname, (uint)length, buffer, mysql_error(&mysql));
 
2089
                    my_progname, (uint)length, buffer, drizzle_error(&drizzle));
2090
2090
            exit(1);
2091
2091
          }
2092
2092
        }
2093
2093
      }
2094
2094
      else
2095
2095
      {
2096
 
        if (run_query(&mysql, ptr->string, ptr->length))
 
2096
        if (run_query(&drizzle, ptr->string, ptr->length))
2097
2097
        {
2098
2098
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2099
 
                  my_progname, (uint)ptr->length, ptr->string, mysql_error(&mysql));
 
2099
                  my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
2100
2100
          exit(1);
2101
2101
        }
2102
2102
      }
2105
2105
      {
2106
2106
        do
2107
2107
        {
2108
 
          if (mysql_field_count(&mysql))
 
2108
          if (drizzle_field_count(&drizzle))
2109
2109
          {
2110
 
            result= mysql_store_result(&mysql);
2111
 
            while ((row = mysql_fetch_row(result)))
 
2110
            result= drizzle_store_result(&drizzle);
 
2111
            while ((row = drizzle_fetch_row(result)))
2112
2112
              counter++;
2113
 
            mysql_free_result(result);
 
2113
            drizzle_free_result(result);
2114
2114
          }
2115
 
        } while(mysql_next_result(&mysql) == 0);
 
2115
        } while(drizzle_next_result(&drizzle) == 0);
2116
2116
      }
2117
2117
      queries++;
2118
2118
 
2119
2119
      if (commit_rate && (++commit_counter == commit_rate))
2120
2120
      {
2121
2121
        commit_counter= 0;
2122
 
        run_query(&mysql, "COMMIT", strlen("COMMIT"));
 
2122
        run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2123
2123
      }
2124
2124
 
2125
2125
      /* If the timer is set, and the alarm is not active then end */
2140
2140
 
2141
2141
end:
2142
2142
  if (commit_rate)
2143
 
    run_query(&mysql, "COMMIT", strlen("COMMIT"));
 
2143
    run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2144
2144
 
2145
 
  slap_close(&mysql);
 
2145
  slap_close(&drizzle);
2146
2146
 
2147
2147
  pthread_mutex_lock(&counter_mutex);
2148
2148
  thread_counter--;
2151
2151
 
2152
2152
  my_free(con, MYF(0));
2153
2153
 
2154
 
  mysql_thread_end();
 
2154
  drizzle_thread_end();
2155
2155
  return(0);
2156
2156
}
2157
2157
 
2184
2184
 
2185
2185
    bzero(buffer, HUGE_STRING_LENGTH);
2186
2186
 
2187
 
    string= strchr(begin_ptr, delm); 
 
2187
    string= strchr(begin_ptr, delm);
2188
2188
 
2189
2189
    if (string)
2190
2190
    {
2243
2243
 
2244
2244
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2245
2245
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2246
 
       (retstr= strchr(ptr, delm)); 
 
2246
       (retstr= strchr(ptr, delm));
2247
2247
       tmp->next=  (statement *)my_malloc(sizeof(statement),
2248
2248
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
2249
2249
       tmp= tmp->next)
2258
2258
 
2259
2259
  if (ptr != script+length)
2260
2260
  {
2261
 
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr), 
 
2261
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2262
2262
                                       MYF(MY_FAE));
2263
2263
    tmp->length= (size_t)((script + length) - ptr);
2264
2264
    count++;
2283
2283
 
2284
2284
  for (;*ptr; ptr++)
2285
2285
    if (*ptr == ',') count++;
2286
 
  
 
2286
 
2287
2287
  /* One extra spot for the NULL */
2288
 
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1), 
 
2288
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
2289
2289
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
2290
2290
 
2291
2291
  ptr= (char *)string;
2319
2319
         con->min_timing / 1000, con->min_timing % 1000);
2320
2320
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2321
2321
         con->max_timing / 1000, con->max_timing % 1000);
2322
 
  printf("\tTotal time for tests: %ld.%03ld seconds\n", 
 
2322
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2323
2323
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2324
2324
  printf("\tStandard Deviation: %ld.%03ld\n", con->std_dev / 1000, con->std_dev % 1000);
2325
2325
  printf("\tNumber of queries in create queries: %llu\n", con->create_count);
2326
 
  printf("\tNumber of clients running queries: %u/%u\n", 
 
2326
  printf("\tNumber of clients running queries: %u/%u\n",
2327
2327
         con->users, con->real_users);
2328
2328
  printf("\tNumber of times test was run: %u\n", iterations);
2329
 
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows); 
 
2329
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows);
2330
2330
  printf("\n");
2331
2331
}
2332
2332
 
2351
2351
      else
2352
2352
        label_buffer[x]= opt_label[x] ;
2353
2353
    }
2354
 
  } 
 
2354
  }
2355
2355
  else if (opt_auto_generate_sql_type)
2356
2356
  {
2357
2357
    string_len= strlen(opt_auto_generate_sql_type);
2367
2367
  else
2368
2368
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
2369
2369
 
2370
 
  snprintf(buffer, HUGE_STRING_LENGTH, 
 
2370
  snprintf(buffer, HUGE_STRING_LENGTH,
2371
2371
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%u,%u,%u,%llu\n",
2372
2372
           con->engine ? con->engine : "", /* Storage engine we ran against */
2373
2373
           label_buffer, /* Load type */
2390
2390
  stats *ptr;
2391
2391
  unsigned int x;
2392
2392
 
2393
 
  con->min_timing= sptr->timing; 
 
2393
  con->min_timing= sptr->timing;
2394
2394
  con->max_timing= sptr->timing;
2395
2395
  con->min_rows= sptr->rows;
2396
2396
  con->max_rows= sptr->rows;
2397
 
  
 
2397
 
2398
2398
  /* At the moment we assume uniform */
2399
2399
  con->users= sptr->users;
2400
2400
  con->real_users= sptr->real_users;
2401
2401
  con->avg_rows= sptr->rows;
2402
 
  
 
2402
 
2403
2403
  /* With no next, we know it is the last element that was malloced */
2404
2404
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2405
2405
  {
2421
2421
  standard_deviation(con, sptr);
2422
2422
 
2423
2423
  /* Now we do the create time operations */
2424
 
  con->create_min_timing= sptr->create_timing; 
 
2424
  con->create_min_timing= sptr->create_timing;
2425
2425
  con->create_max_timing= sptr->create_timing;
2426
 
  
 
2426
 
2427
2427
  /* At the moment we assume uniform */
2428
2428
  con->create_count= sptr->create_count;
2429
 
  
 
2429
 
2430
2430
  /* With no next, we know it is the last element that was malloced */
2431
2431
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2432
2432
  {
2451
2451
  {
2452
2452
    nptr= ptr->next;
2453
2453
    if (ptr->string)
2454
 
      my_free(ptr->string, MYF(0)); 
 
2454
      my_free(ptr->string, MYF(0));
2455
2455
    if (ptr->option)
2456
 
      my_free(ptr->option, MYF(0)); 
 
2456
      my_free(ptr->option, MYF(0));
2457
2457
    my_free(ptr, MYF(0));
2458
2458
  }
2459
2459
}
2469
2469
  {
2470
2470
    nptr= ptr->next;
2471
2471
    if (ptr->string)
2472
 
      my_free(ptr->string, MYF(0)); 
 
2472
      my_free(ptr->string, MYF(0));
2473
2473
    my_free(ptr, MYF(0));
2474
2474
  }
2475
2475
}
2476
2476
 
2477
 
void 
2478
 
slap_close(MYSQL *mysql)
 
2477
void
 
2478
slap_close(DRIZZLE *drizzle)
2479
2479
{
2480
 
  if (opt_only_print) 
 
2480
  if (opt_only_print)
2481
2481
    return;
2482
2482
 
2483
 
  mysql_close(mysql);
 
2483
  drizzle_close(drizzle);
2484
2484
}
2485
2485
 
2486
 
void 
2487
 
slap_connect(MYSQL *mysql, bool connect_to_schema)
 
2486
void
 
2487
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2488
2488
{
2489
2489
  /* Connect to server */
2490
2490
  static ulong connection_retry_sleep= 100000; /* Microseconds */
2491
2491
  int x, connect_error= 1;
2492
2492
 
2493
 
  if (opt_only_print) 
 
2493
  if (opt_only_print)
2494
2494
    return;
2495
2495
 
2496
2496
  if (opt_delayed_start)
2497
2497
    my_sleep(random()%opt_delayed_start);
2498
2498
 
2499
 
  drizzle_create(mysql);
 
2499
  drizzle_create(drizzle);
2500
2500
 
2501
2501
  if (opt_compress)
2502
 
    mysql_options(mysql,MYSQL_OPT_COMPRESS,NullS);
 
2502
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
2503
2503
  /* We always do opt_protocol to TCP/IP */
2504
 
  mysql_options(mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
2505
 
  mysql_options(mysql, MYSQL_SET_CHARSET_NAME, default_charset);
 
2504
  drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
 
2505
  drizzle_options(drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
2506
2506
 
2507
2507
  for (x= 0; x < 10; x++)
2508
2508
  {
2509
2509
 
2510
2510
 
2511
 
    if (mysql_real_connect(mysql, host, user, opt_password,
 
2511
    if (drizzle_connect(drizzle, host, user, opt_password,
2512
2512
                           connect_to_schema ? create_schema_string : NULL,
2513
 
                           opt_mysql_port,
2514
 
                           opt_mysql_unix_port,
 
2513
                           opt_drizzle_port,
 
2514
                           opt_drizzle_unix_port,
2515
2515
                           connect_flags))
2516
2516
    {
2517
2517
      /* Connect suceeded */
2523
2523
  if (connect_error)
2524
2524
  {
2525
2525
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2526
 
            my_progname, mysql_errno(mysql), mysql_error(mysql));
 
2526
            my_progname, drizzle_errno(drizzle), drizzle_error(drizzle));
2527
2527
    exit(1);
2528
2528
  }
2529
2529
 
2530
2530
  return;
2531
2531
}
2532
2532
 
2533
 
void 
 
2533
void
2534
2534
standard_deviation (conclusions *con, stats *sptr)
2535
2535
{
2536
2536
  unsigned int x;