~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Jay Pipes
  • Date: 2009-02-21 16:00:06 UTC
  • mto: (907.1.1 trunk-with-temporal)
  • mto: This revision was merged to the branch mainline in revision 908.
  • Revision ID: jpipes@serialcoder-20090221160006-vnk3wt4qbcz62eru
Removes the TIME column type and related time functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
#include <stdarg.h>
82
82
#include <sys/types.h>
83
83
#include <sys/wait.h>
84
 
#ifdef HAVE_SYS_STAT_H
85
 
# include <sys/stat.h>
86
 
#endif
87
 
#include <fcntl.h>
88
 
#include <math.h>
89
84
#include <ctype.h>
90
 
#include <cassert>
91
 
#include <cstdlib>
92
85
#include <string>
93
86
 
94
 
#include <pthread.h>
95
 
 
96
87
/* Added this for string translation. */
97
88
#include <drizzled/gettext.h>
98
89
 
 
90
#include CMATH_H
 
91
 
 
92
#if defined(CMATH_NAMESPACE)
 
93
using namespace CMATH_NAMESPACE;
 
94
#endif
 
95
 
99
96
using namespace std;
100
 
using namespace drizzled;
101
97
 
102
98
#ifdef HAVE_SMEM
103
99
static char *shared_memory_base_name=0;
104
100
#endif
105
101
 
 
102
extern "C"
 
103
bool get_one_option(int optid, const struct my_option *, char *argument);
 
104
 
106
105
/* Global Thread counter */
107
106
uint32_t thread_counter;
108
107
pthread_mutex_t counter_mutex;
128
127
  *user_supplied_post_statements= NULL,
129
128
  *default_engine= NULL,
130
129
  *pre_system= NULL,
131
 
  *post_system= NULL;
 
130
  *post_system= NULL,
 
131
  *opt_drizzle_unix_port= NULL;
132
132
 
133
133
const char *delimiter= "\n";
134
134
 
135
135
const char *create_schema_string= "drizzleslap";
136
136
 
137
 
static bool opt_mysql= false;
138
137
static bool opt_preserve= true;
 
138
static bool debug_info_flag= false, debug_check_flag= false;
139
139
static bool opt_only_print= false;
140
140
static bool opt_burnin= false;
141
141
static bool opt_ignore_sql_errors= false;
142
 
static bool tty_password= false,
 
142
static bool opt_compress= false, tty_password= false,
143
143
  opt_silent= false,
144
144
  auto_generate_sql_autoincrement= false,
145
145
  auto_generate_sql_guid_primary= false,
146
146
  auto_generate_sql= false;
147
147
const char *opt_auto_generate_sql_type= "mixed";
148
148
 
 
149
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
 
150
  CLIENT_MULTI_STATEMENTS;
 
151
 
149
152
static int verbose, delimiter_length;
150
153
static uint32_t commit_rate;
151
154
static uint32_t detach_rate;
168
171
static unsigned int num_int_cols_index= 0;
169
172
static unsigned int num_char_cols_index= 0;
170
173
static unsigned int iterations;
 
174
static uint32_t my_end_arg= 0;
171
175
static uint64_t actual_queries= 0;
172
176
static uint64_t auto_actual_queries;
173
177
static uint64_t auto_generate_sql_unique_write_number;
181
185
 
182
186
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
183
187
const char *opt_csv_str;
184
 
int csv_file;
 
188
File csv_file;
185
189
 
186
190
static int get_options(int *argc,char ***argv);
187
191
static uint32_t opt_drizzle_port= 0;
277
281
uint32_t parse_comma(const char *string, uint32_t **range);
278
282
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
279
283
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
280
 
static int drop_schema(drizzle_con_st *con, const char *db);
 
284
static int drop_schema(DRIZZLE *drizzle, const char *db);
281
285
uint32_t get_random_string(char *buf, size_t size);
282
286
static statement *build_table_string(void);
283
287
static statement *build_insert_string(void);
284
288
static statement *build_update_string(void);
285
289
static statement * build_select_string(bool key);
286
 
static int generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt);
 
290
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
287
291
static int drop_primary_key_list(void);
288
 
static int create_schema(drizzle_con_st *con, const char *db, statement *stmt,
 
292
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
289
293
                         option_string *engine_stmt, stats *sptr);
290
294
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
291
295
                         uint64_t limit);
293
297
extern "C" pthread_handler_t timer_thread(void *p);
294
298
void statement_cleanup(statement *stmt);
295
299
void option_cleanup(option_string *stmt);
296
 
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr);
297
 
static int run_statements(drizzle_con_st *con, statement *stmt);
298
 
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
299
 
void slap_close(drizzle_con_st *con);
300
 
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
 
300
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr);
 
301
static int run_statements(DRIZZLE *drizzle, statement *stmt);
 
302
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
 
303
void slap_close(DRIZZLE *drizzle);
 
304
static int run_query(DRIZZLE *drizzle, const char *query, int len);
301
305
void standard_deviation (conclusions *con, stats *sptr);
302
306
 
303
307
static const char ALPHANUMERICS[]=
319
323
 
320
324
int main(int argc, char **argv)
321
325
{
322
 
  drizzle_con_st con;
 
326
  DRIZZLE drizzle;
323
327
  option_string *eptr;
324
328
  unsigned int x;
325
329
 
326
 
  internal::my_init();
 
330
  my_init();
327
331
 
328
332
  MY_INIT(argv[0]);
329
333
 
330
 
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
 
334
  load_defaults("drizzle",load_default_groups,&argc,&argv);
331
335
  defaults_argv=argv;
332
336
  if (get_options(&argc,&argv))
333
337
  {
334
 
    internal::free_defaults(defaults_argv);
335
 
    internal::my_end();
 
338
    free_defaults(defaults_argv);
 
339
    my_end(0);
336
340
    exit(1);
337
341
  }
338
342
 
349
353
 
350
354
  if (argc > 2)
351
355
  {
352
 
    fprintf(stderr,"%s: Too many arguments\n",internal::my_progname);
353
 
    internal::free_defaults(defaults_argv);
354
 
    internal::my_end();
 
356
    fprintf(stderr,"%s: Too many arguments\n",my_progname);
 
357
    free_defaults(defaults_argv);
 
358
    my_end(0);
355
359
    exit(1);
356
360
  }
357
361
 
358
 
  slap_connect(&con, false);
 
362
  slap_connect(&drizzle, false);
359
363
 
360
364
  pthread_mutex_init(&counter_mutex, NULL);
361
365
  pthread_cond_init(&count_threshhold, NULL);
379
383
    if (*concurrency)
380
384
    {
381
385
      for (current= concurrency; current && *current; current++)
382
 
        concurrency_loop(&con, *current, eptr);
 
386
        concurrency_loop(&drizzle, *current, eptr);
383
387
    }
384
388
    else
385
389
    {
386
390
      uint32_t infinite= 1;
387
391
      do {
388
 
        concurrency_loop(&con, infinite, eptr);
 
392
        concurrency_loop(&drizzle, infinite, eptr);
389
393
      }
390
394
      while (infinite++);
391
395
    }
392
396
 
393
397
    if (!opt_preserve)
394
 
      drop_schema(&con, create_schema_string);
 
398
      drop_schema(&drizzle, create_schema_string);
395
399
 
396
400
  } while (eptr ? (eptr= eptr->next) : 0);
397
401
 
405
409
  pthread_mutex_destroy(&timer_alarm_mutex);
406
410
  pthread_cond_destroy(&timer_alarm_threshold);
407
411
 
408
 
  slap_close(&con);
 
412
  slap_close(&drizzle);
409
413
 
410
414
  /* now free all the strings we created */
411
415
  if (opt_password)
426
430
  if (shared_memory_base_name)
427
431
    free(shared_memory_base_name);
428
432
#endif
429
 
  internal::free_defaults(defaults_argv);
430
 
  internal::my_end();
 
433
  free_defaults(defaults_argv);
 
434
  my_end(my_end_arg);
431
435
 
432
436
  return 0;
433
437
}
434
438
 
435
 
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr)
 
439
void concurrency_loop(DRIZZLE *drizzle, uint32_t current, option_string *eptr)
436
440
{
437
441
  unsigned int x;
438
442
  stats *head_sptr;
465
469
      data in the table.
466
470
    */
467
471
    if (opt_preserve == false)
468
 
      drop_schema(con, create_schema_string);
 
472
      drop_schema(drizzle, create_schema_string);
469
473
 
470
474
    /* First we create */
471
475
    if (create_statements)
472
 
      create_schema(con, create_schema_string, create_statements, eptr, sptr);
 
476
      create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
473
477
 
474
478
    /*
475
479
      If we generated GUID we need to build a list of them from creation that
478
482
    if (verbose >= 2)
479
483
      printf("Generating primary key list\n");
480
484
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
481
 
      generate_primary_key_list(con, eptr);
 
485
      generate_primary_key_list(drizzle, eptr);
482
486
 
483
487
    if (commit_rate)
484
 
      run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
488
      run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
485
489
 
486
490
    if (pre_system)
487
 
    {
488
 
      int ret= system(pre_system);
489
 
      assert(ret != -1);
490
 
    }
491
 
       
 
491
      assert(system(pre_system)!=-1);
492
492
 
493
493
    /*
494
494
      Pre statements are always run after all other logic so they can
495
495
      correct/adjust any item that they want.
496
496
    */
497
497
    if (pre_statements)
498
 
      run_statements(con, pre_statements);
 
498
      run_statements(drizzle, pre_statements);
499
499
 
500
500
    run_scheduler(sptr, query_statements, current, client_limit);
501
501
 
502
502
    if (post_statements)
503
 
      run_statements(con, post_statements);
 
503
      run_statements(drizzle, post_statements);
504
504
 
505
505
    if (post_system)
506
 
    {
507
 
      int ret=  system(post_system);
508
 
      assert(ret !=-1);
509
 
    }
 
506
      assert(system(post_system)!=-1);
510
507
 
511
508
    /* We are finished with this run */
512
509
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
528
525
}
529
526
 
530
527
 
531
 
static struct option my_long_options[] =
 
528
static struct my_option my_long_options[] =
532
529
{
533
530
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
534
531
   0, 0, 0, 0, 0, 0},
593
590
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
594
591
   (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
595
592
   0, 0, 0, 0, 0, 0},
 
593
  {"compress", 'C', "Use compression in server/client protocol.",
 
594
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
595
   0, 0, 0},
596
596
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
597
597
   (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
598
598
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
606
606
   "Generate CSV output to named file or to stdout if no file is named.",
607
607
   (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
608
608
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
609
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
 
610
    (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
611
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
612
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
 
613
    (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
609
614
  {"delayed-start", OPT_SLAP_DELAYED_START,
610
615
   "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
611
616
   (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
628
633
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
629
634
   (char**) &opt_label, (char**) &opt_label, 0,
630
635
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
631
 
  {"mysql", 'm', N_("Use MySQL Protocol."),
632
 
   (char**) &opt_mysql, (char**) &opt_mysql, 0, GET_BOOL, NO_ARG, 1, 0, 0,
633
 
   0, 0, 0},
634
636
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
635
637
   "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. ",
636
638
   (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
691
693
  {"silent", 's', "Run program in silent mode - no output.",
692
694
   (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
693
695
   0, 0, 0, 0, 0, 0},
 
696
  {"socket", 'S', "Socket file to use for connection.",
 
697
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
 
698
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
694
699
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
695
700
   "Require drizzleslap to run each specific test a certain amount of time in seconds.",
696
701
   (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
697
702
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
703
#ifndef DONT_ALLOW_USER_CHANGE
698
704
  {"user", 'u', "User for login if not current user.", (char**) &user,
699
705
   (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
706
#endif
700
707
  {"verbose", 'v',
701
708
   "More verbose output; you can use this multiple times to get even more "
702
709
   "verbose output.", (char**) &verbose, (char**) &verbose, 0,
709
716
 
710
717
static void print_version(void)
711
718
{
712
 
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
713
 
         drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
 
719
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
 
720
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
714
721
}
715
722
 
716
723
 
722
729
       \nand you are welcome to modify and redistribute it under the GPL \
723
730
       license\n");
724
731
  puts("Run a query multiple times against the server\n");
725
 
  printf("Usage: %s [OPTIONS]\n",internal::my_progname);
726
 
  internal::print_defaults("drizzle",load_default_groups);
 
732
  printf("Usage: %s [OPTIONS]\n",my_progname);
 
733
  print_defaults("drizzle",load_default_groups);
727
734
  my_print_help(my_long_options);
728
735
}
729
736
 
730
 
static int get_one_option(int optid, const struct option *, char *argument)
 
737
bool get_one_option(int optid, const struct my_option *, char *argument)
731
738
{
732
739
  char *endchar= NULL;
733
740
  uint64_t temp_drizzle_port= 0;
742
749
    if (strlen(endchar) != 0)
743
750
    {
744
751
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
745
 
      return EXIT_ARGUMENT_INVALID;
 
752
      exit(1);
746
753
    }
747
754
    /* If the port number is > 65535 it is not a valid port
748
755
       This also helps with potential data loss casting unsigned long to a
750
757
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
751
758
    {
752
759
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
753
 
      return EXIT_ARGUMENT_INVALID;
 
760
      exit(1);
754
761
    }
755
762
    else
756
763
    {
768
775
      {
769
776
        fprintf(stderr, "Memory allocation error while copying password. "
770
777
                        "Aborting.\n");
771
 
        return EXIT_OUT_OF_MEMORY;
 
778
        exit(ENOMEM);
772
779
      }
773
780
      while (*argument)
774
781
      {
1284
1291
 
1285
1292
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1286
1293
    exit(ho_error);
 
1294
  if (debug_info_flag)
 
1295
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
1296
  if (debug_check_flag)
 
1297
    my_end_arg= MY_CHECK_ERROR;
1287
1298
 
1288
1299
  if (!user)
1289
1300
    user= (char *)"root";
1296
1307
  {
1297
1308
    fprintf(stderr,
1298
1309
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1299
 
            internal::my_progname);
 
1310
            my_progname);
1300
1311
    exit(1);
1301
1312
  }
1302
1313
 
1305
1316
  {
1306
1317
    fprintf(stderr,
1307
1318
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1308
 
            internal::my_progname);
 
1319
            my_progname);
1309
1320
    exit(1);
1310
1321
  }
1311
1322
 
1313
1324
  {
1314
1325
    fprintf(stderr,
1315
1326
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1316
 
            internal::my_progname);
 
1327
            my_progname);
1317
1328
    exit(1);
1318
1329
  }
1319
1330
 
1329
1340
    }
1330
1341
    else
1331
1342
    {
1332
 
      if ((csv_file= open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, 
1333
 
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
 
1343
      if ((csv_file= my_open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, MYF(0)))
 
1344
          == -1)
1334
1345
      {
1335
1346
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1336
 
                internal::my_progname, opt_csv_str);
 
1347
                my_progname, opt_csv_str);
1337
1348
        exit(1);
1338
1349
      }
1339
1350
    }
1454
1465
        {
1455
1466
          fprintf(stderr,
1456
1467
                  "%s: Can't perform key test without a primary key!\n",
1457
 
                  internal::my_progname);
 
1468
                  my_progname);
1458
1469
          exit(1);
1459
1470
        }
1460
1471
 
1490
1501
        {
1491
1502
          fprintf(stderr,
1492
1503
                  "%s: Can't perform update test without a primary key!\n",
1493
 
                  internal::my_progname);
 
1504
                  my_progname);
1494
1505
          exit(1);
1495
1506
        }
1496
1507
 
1534
1545
  {
1535
1546
    if (create_string && !stat(create_string, &sbuf))
1536
1547
    {
1537
 
      int data_file;
 
1548
      File data_file;
1538
1549
      if (!S_ISREG(sbuf.st_mode))
1539
1550
      {
1540
1551
        fprintf(stderr,"%s: Create file was not a regular file\n",
1541
 
                internal::my_progname);
 
1552
                my_progname);
1542
1553
        exit(1);
1543
1554
      }
1544
 
      if ((data_file= open(create_string, O_RDWR)) == -1)
 
1555
      if ((data_file= my_open(create_string, O_RDWR, MYF(0))) == -1)
1545
1556
      {
1546
 
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
 
1557
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1547
1558
        exit(1);
1548
1559
      }
1549
1560
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1591
1602
 
1592
1603
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1593
1604
    {
1594
 
      int data_file;
 
1605
      File data_file;
1595
1606
      if (!S_ISREG(sbuf.st_mode))
1596
1607
      {
1597
1608
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1598
 
                internal::my_progname);
 
1609
                my_progname);
1599
1610
        exit(1);
1600
1611
      }
1601
 
      if ((data_file= open(user_supplied_query, O_RDWR)) == -1)
 
1612
      if ((data_file= my_open(user_supplied_query, O_RDWR, MYF(0))) == -1)
1602
1613
      {
1603
 
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1614
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1604
1615
        exit(1);
1605
1616
      }
1606
1617
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1638
1649
  if (user_supplied_pre_statements
1639
1650
      && !stat(user_supplied_pre_statements, &sbuf))
1640
1651
  {
1641
 
    int data_file;
 
1652
    File data_file;
1642
1653
    if (!S_ISREG(sbuf.st_mode))
1643
1654
    {
1644
1655
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1645
 
              internal::my_progname);
 
1656
              my_progname);
1646
1657
      exit(1);
1647
1658
    }
1648
 
    if ((data_file= open(user_supplied_pre_statements, O_RDWR)) == -1)
 
1659
    if ((data_file= my_open(user_supplied_pre_statements, O_RDWR, MYF(0))) == -1)
1649
1660
    {
1650
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1661
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1651
1662
      exit(1);
1652
1663
    }
1653
1664
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1685
1696
  if (user_supplied_post_statements
1686
1697
      && !stat(user_supplied_post_statements, &sbuf))
1687
1698
  {
1688
 
    int data_file;
 
1699
    File data_file;
1689
1700
    if (!S_ISREG(sbuf.st_mode))
1690
1701
    {
1691
1702
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1692
 
              internal::my_progname);
 
1703
              my_progname);
1693
1704
      exit(1);
1694
1705
    }
1695
 
    if ((data_file= open(user_supplied_post_statements, O_RDWR)) == -1)
 
1706
    if ((data_file= my_open(user_supplied_post_statements, O_RDWR, MYF(0))) == -1)
1696
1707
    {
1697
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1708
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1698
1709
      exit(1);
1699
1710
    }
1700
1711
 
1737
1748
    parse_option(default_engine, &engine_options, ',');
1738
1749
 
1739
1750
  if (tty_password)
1740
 
    opt_password= client_get_tty_password(NULL);
 
1751
    opt_password= drizzleclient_get_tty_password(NULL);
1741
1752
  return(0);
1742
1753
}
1743
1754
 
1744
1755
 
1745
 
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
1746
 
                     const char *query, int len)
 
1756
static int run_query(DRIZZLE *drizzle, const char *query, int len)
1747
1757
{
1748
 
  drizzle_return_t ret;
1749
 
  drizzle_result_st result_buffer;
1750
 
 
1751
1758
  if (opt_only_print)
1752
1759
  {
1753
1760
    printf("%.*s;\n", len, query);
1756
1763
 
1757
1764
  if (verbose >= 3)
1758
1765
    printf("%.*s;\n", len, query);
1759
 
 
1760
 
  if (result == NULL)
1761
 
    result= &result_buffer;
1762
 
 
1763
 
  result= drizzle_query(con, result, query, len, &ret);
1764
 
 
1765
 
  if (ret == DRIZZLE_RETURN_OK)
1766
 
    ret= drizzle_result_buffer(result);
1767
 
 
1768
 
  if (result == &result_buffer)
1769
 
    drizzle_result_free(result);
1770
 
    
1771
 
  return ret;
 
1766
  return drizzleclient_real_query(drizzle, query, len);
1772
1767
}
1773
1768
 
1774
1769
 
1775
1770
static int
1776
 
generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt)
 
1771
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
1777
1772
{
1778
 
  drizzle_result_st result;
1779
 
  drizzle_row_t row;
 
1773
  DRIZZLE_RES *result;
 
1774
  DRIZZLE_ROW row;
1780
1775
  uint64_t counter;
1781
1776
 
1782
1777
 
1807
1802
  }
1808
1803
  else
1809
1804
  {
1810
 
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
 
1805
    if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
1811
1806
    {
1812
 
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
1813
 
              drizzle_con_error(con));
 
1807
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
 
1808
              drizzleclient_error(drizzle));
1814
1809
      exit(1);
1815
1810
    }
1816
1811
 
1817
 
    uint64_t num_rows_ret= drizzle_result_row_count(&result);
 
1812
    result= drizzleclient_store_result(drizzle);
 
1813
    uint64_t num_rows_ret= drizzleclient_num_rows(result);
1818
1814
    if (num_rows_ret > SIZE_MAX)
1819
1815
    {
1820
1816
      fprintf(stderr, "More primary keys than than architecture supports\n");
1836
1832
        exit(1);
1837
1833
      }
1838
1834
      memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
1839
 
      row= drizzle_row_next(&result);
 
1835
      row= drizzleclient_fetch_row(result);
1840
1836
      for (counter= 0; counter < primary_keys_number_of;
1841
 
           counter++, row= drizzle_row_next(&result))
 
1837
           counter++, row= drizzleclient_fetch_row(result))
1842
1838
      {
1843
1839
        primary_keys[counter]= strdup(row[0]);
1844
1840
        if (primary_keys[counter] == NULL)
1849
1845
      }
1850
1846
    }
1851
1847
 
1852
 
    drizzle_result_free(&result);
 
1848
    drizzleclient_free_result(result);
1853
1849
  }
1854
1850
 
1855
1851
  return(0);
1872
1868
}
1873
1869
 
1874
1870
static int
1875
 
create_schema(drizzle_con_st *con, const char *db, statement *stmt,
 
1871
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
1876
1872
              option_string *engine_stmt, stats *sptr)
1877
1873
{
1878
1874
  char query[HUGE_STRING_LENGTH];
1890
1886
  if (verbose >= 2)
1891
1887
    printf("Loading Pre-data\n");
1892
1888
 
1893
 
  if (run_query(con, NULL, query, len))
 
1889
  if (run_query(drizzle, query, len))
1894
1890
  {
1895
 
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
1896
 
            drizzle_con_error(con));
 
1891
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
 
1892
            drizzleclient_error(drizzle));
1897
1893
    exit(1);
1898
1894
  }
1899
1895
  else
1907
1903
  }
1908
1904
  else
1909
1905
  {
1910
 
    drizzle_result_st result;
1911
 
    drizzle_return_t ret;
1912
 
 
1913
1906
    if (verbose >= 3)
1914
1907
      printf("%s;\n", query);
1915
1908
 
1916
 
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
1917
 
        ret != DRIZZLE_RETURN_OK)
 
1909
    if (drizzleclient_select_db(drizzle,  db))
1918
1910
    {
1919
 
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
1920
 
              ret == DRIZZLE_RETURN_ERROR_CODE ?
1921
 
              drizzle_result_error(&result) : drizzle_con_error(con));
 
1911
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
 
1912
              drizzleclient_error(drizzle));
1922
1913
      exit(1);
1923
1914
    }
1924
 
    drizzle_result_free(&result);
1925
1915
    sptr->create_count++;
1926
1916
  }
1927
1917
 
1929
1919
  {
1930
1920
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1931
1921
                  engine_stmt->string);
1932
 
    if (run_query(con, NULL, query, len))
 
1922
    if (run_query(drizzle, query, len))
1933
1923
    {
1934
 
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
1935
 
              drizzle_con_error(con));
 
1924
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
 
1925
              drizzleclient_error(drizzle));
1936
1926
      exit(1);
1937
1927
    }
1938
1928
    sptr->create_count++;
1953
1943
 
1954
1944
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1955
1945
               engine_stmt->option);
1956
 
      if (run_query(con, NULL, buffer, strlen(buffer)))
 
1946
      if (run_query(drizzle, buffer, strlen(buffer)))
1957
1947
      {
1958
1948
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1959
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
1949
                my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1960
1950
        if (!opt_ignore_sql_errors)
1961
1951
          exit(1);
1962
1952
      }
1964
1954
    }
1965
1955
    else
1966
1956
    {
1967
 
      if (run_query(con, NULL, ptr->string, ptr->length))
 
1957
      if (run_query(drizzle, ptr->string, ptr->length))
1968
1958
      {
1969
1959
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1970
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
1960
                my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
1971
1961
        if (!opt_ignore_sql_errors)
1972
1962
          exit(1);
1973
1963
      }
1990
1980
}
1991
1981
 
1992
1982
static int
1993
 
drop_schema(drizzle_con_st *con, const char *db)
 
1983
drop_schema(DRIZZLE *drizzle, const char *db)
1994
1984
{
1995
1985
  char query[HUGE_STRING_LENGTH];
1996
1986
  int len;
1997
1987
 
1998
1988
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1999
1989
 
2000
 
  if (run_query(con, NULL, query, len))
 
1990
  if (run_query(drizzle, query, len))
2001
1991
  {
2002
1992
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
2003
 
            internal::my_progname, db, drizzle_con_error(con));
 
1993
            my_progname, db, drizzleclient_error(drizzle));
2004
1994
    exit(1);
2005
1995
  }
2006
1996
 
2010
2000
}
2011
2001
 
2012
2002
static int
2013
 
run_statements(drizzle_con_st *con, statement *stmt)
 
2003
run_statements(DRIZZLE *drizzle, statement *stmt)
2014
2004
{
2015
2005
  statement *ptr;
 
2006
  DRIZZLE_RES *result;
 
2007
 
2016
2008
 
2017
2009
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
2018
2010
  {
2019
 
    if (run_query(con, NULL, ptr->string, ptr->length))
 
2011
    if (run_query(drizzle, ptr->string, ptr->length))
2020
2012
    {
2021
2013
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2022
 
              internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
2014
              my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(drizzle));
2023
2015
      exit(1);
2024
2016
    }
 
2017
    if (!opt_only_print)
 
2018
    {
 
2019
      if (drizzleclient_field_count(drizzle))
 
2020
      {
 
2021
        result= drizzleclient_store_result(drizzle);
 
2022
        drizzleclient_free_result(result);
 
2023
      }
 
2024
    }
2025
2025
  }
2026
2026
 
2027
2027
  return(0);
2083
2083
        if (pthread_create(&mainthread, &attr, run_task,
2084
2084
                           (void *)con) != 0)
2085
2085
        {
2086
 
          fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
 
2086
          fprintf(stderr,"%s: Could not create thread\n", my_progname);
2087
2087
          exit(1);
2088
2088
        }
2089
2089
        thread_counter++;
2103
2103
    if (pthread_create(&mainthread, &attr, timer_thread,
2104
2104
                       (void *)&opt_timer_length) != 0)
2105
2105
    {
2106
 
      fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
 
2106
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
2107
2107
      exit(1);
2108
2108
    }
2109
2109
  }
2178
2178
  uint64_t counter= 0, queries;
2179
2179
  uint64_t detach_counter;
2180
2180
  unsigned int commit_counter;
2181
 
  drizzle_con_st con;
2182
 
  drizzle_result_st result;
2183
 
  drizzle_row_t row;
 
2181
  DRIZZLE drizzle;
 
2182
  DRIZZLE_RES *result;
 
2183
  DRIZZLE_ROW row;
2184
2184
  statement *ptr;
2185
 
  thread_context *ctx= (thread_context *)p;
 
2185
  thread_context *con= (thread_context *)p;
2186
2186
 
2187
2187
  pthread_mutex_lock(&sleeper_mutex);
2188
2188
  while (master_wakeup)
2191
2191
  }
2192
2192
  pthread_mutex_unlock(&sleeper_mutex);
2193
2193
 
2194
 
  slap_connect(&con, true);
 
2194
  slap_connect(&drizzle, true);
2195
2195
 
2196
2196
  if (verbose >= 3)
2197
2197
    printf("connected!\n");
2199
2199
 
2200
2200
  commit_counter= 0;
2201
2201
  if (commit_rate)
2202
 
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
2202
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2203
2203
 
2204
2204
limit_not_met:
2205
 
  for (ptr= ctx->stmt, detach_counter= 0;
 
2205
  for (ptr= con->stmt, detach_counter= 0;
2206
2206
       ptr && ptr->length;
2207
2207
       ptr= ptr->next, detach_counter++)
2208
2208
  {
2209
2209
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2210
2210
    {
2211
 
      slap_close(&con);
2212
 
      slap_connect(&con, true);
 
2211
      slap_close(&drizzle);
 
2212
      slap_connect(&drizzle, true);
2213
2213
    }
2214
2214
 
2215
2215
    /*
2241
2241
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2242
2242
                         (int)ptr->length, ptr->string, key);
2243
2243
 
2244
 
        if (run_query(&con, &result, buffer, length))
 
2244
        if (run_query(&drizzle, buffer, length))
2245
2245
        {
2246
2246
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2247
 
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
 
2247
                  my_progname, (uint32_t)length, buffer, drizzleclient_error(&drizzle));
2248
2248
          exit(1);
2249
2249
        }
2250
2250
      }
2251
2251
    }
2252
2252
    else
2253
2253
    {
2254
 
      if (run_query(&con, &result, ptr->string, ptr->length))
 
2254
      if (run_query(&drizzle, ptr->string, ptr->length))
2255
2255
      {
2256
2256
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2257
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
 
2257
                my_progname, (uint32_t)ptr->length, ptr->string, drizzleclient_error(&drizzle));
2258
2258
        exit(1);
2259
2259
      }
2260
2260
    }
2261
2261
 
2262
2262
    if (!opt_only_print)
2263
2263
    {
2264
 
      while ((row = drizzle_row_next(&result)))
2265
 
        counter++;
2266
 
      drizzle_result_free(&result);
 
2264
      do
 
2265
      {
 
2266
        if (drizzleclient_field_count(&drizzle))
 
2267
        {
 
2268
          result= drizzleclient_store_result(&drizzle);
 
2269
          while ((row = drizzleclient_fetch_row(result)))
 
2270
            counter++;
 
2271
          drizzleclient_free_result(result);
 
2272
        }
 
2273
      } while(drizzleclient_next_result(&drizzle) == 0);
2267
2274
    }
2268
2275
    queries++;
2269
2276
 
2270
2277
    if (commit_rate && (++commit_counter == commit_rate))
2271
2278
    {
2272
2279
      commit_counter= 0;
2273
 
      run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
2280
      run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2274
2281
    }
2275
2282
 
2276
2283
    /* If the timer is set, and the alarm is not active then end */
2278
2285
      goto end;
2279
2286
 
2280
2287
    /* If limit has been reached, and we are not in a timer_alarm just end */
2281
 
    if (ctx->limit && queries == ctx->limit && timer_alarm == false)
 
2288
    if (con->limit && queries == con->limit && timer_alarm == false)
2282
2289
      goto end;
2283
2290
  }
2284
2291
 
2285
2292
  if (opt_timer_length && timer_alarm == true)
2286
2293
    goto limit_not_met;
2287
2294
 
2288
 
  if (ctx->limit && queries < ctx->limit)
 
2295
  if (con->limit && queries < con->limit)
2289
2296
    goto limit_not_met;
2290
2297
 
2291
2298
 
2292
2299
end:
2293
2300
  if (commit_rate)
2294
 
    run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
2301
    run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2295
2302
 
2296
 
  slap_close(&con);
 
2303
  slap_close(&drizzle);
2297
2304
 
2298
2305
  pthread_mutex_lock(&counter_mutex);
2299
2306
  thread_counter--;
2300
2307
  pthread_cond_signal(&count_threshhold);
2301
2308
  pthread_mutex_unlock(&counter_mutex);
2302
2309
 
2303
 
  free(ctx);
 
2310
  free(con);
2304
2311
 
2305
2312
  return(0);
2306
2313
}
2415
2422
  uint32_t length= strlen(script);
2416
2423
  uint32_t count= 0; /* We know that there is always one */
2417
2424
 
2418
 
  for (tmp= *sptr= (statement *)calloc(1, sizeof(statement));
 
2425
  for (tmp= *sptr= (statement *)malloc(sizeof(statement));
2419
2426
       (retstr= strchr(ptr, delm));
2420
 
       tmp->next=  (statement *)calloc(1, sizeof(statement)),
 
2427
       tmp->next=  (statement *)malloc(sizeof(statement)),
2421
2428
       tmp= tmp->next)
2422
2429
  {
2423
 
    if (tmp == NULL)
2424
 
    {
2425
 
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2426
 
      exit(1);
2427
 
    }
2428
 
 
 
2430
    memset(tmp, 0, sizeof(statement));
2429
2431
    count++;
2430
2432
    tmp->length= (size_t)(retstr - ptr);
2431
2433
    tmp->string= (char *)malloc(tmp->length + 1);
2432
 
 
2433
2434
    if (tmp->string == NULL)
2434
2435
    {
2435
2436
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2436
2437
      exit(1);
2437
2438
    }
2438
 
 
2439
2439
    memcpy(tmp->string, ptr, tmp->length);
2440
2440
    tmp->string[tmp->length]= 0;
2441
2441
    ptr+= retstr - ptr + 1;
2575
2575
           con->real_users, /* Children used max_timing */
2576
2576
           con->avg_rows  /* Queries run */
2577
2577
           );
2578
 
  internal::my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
 
2578
  my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2579
2579
}
2580
2580
 
2581
2581
void
2669
2669
}
2670
2670
 
2671
2671
void
2672
 
slap_close(drizzle_con_st *con)
 
2672
slap_close(DRIZZLE *drizzle)
2673
2673
{
2674
2674
  if (opt_only_print)
2675
2675
    return;
2676
2676
 
2677
 
  drizzle_free(drizzle_con_drizzle(con));
 
2677
  drizzleclient_close(drizzle);
2678
2678
}
2679
2679
 
2680
2680
void
2681
 
slap_connect(drizzle_con_st *con, bool connect_to_schema)
 
2681
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
2682
2682
{
2683
2683
  /* Connect to server */
2684
2684
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2685
2685
  int x, connect_error= 1;
2686
 
  drizzle_return_t ret;
2687
 
  drizzle_st *drizzle;
2688
2686
 
2689
2687
  if (opt_only_print)
2690
2688
    return;
2692
2690
  if (opt_delayed_start)
2693
2691
    usleep(random()%opt_delayed_start);
2694
2692
 
2695
 
  if ((drizzle= drizzle_create(NULL)) == NULL ||
2696
 
      drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
2697
 
                          opt_password,
2698
 
                          connect_to_schema ? create_schema_string : NULL,
2699
 
                          opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
2700
 
  {
2701
 
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
2702
 
    exit(1);
2703
 
  }
 
2693
  drizzleclient_create(drizzle);
 
2694
 
 
2695
  if (opt_compress)
 
2696
    drizzleclient_options(drizzle,DRIZZLE_OPT_COMPRESS,NULL);
2704
2697
 
2705
2698
  for (x= 0; x < 10; x++)
2706
2699
  {
2707
 
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
 
2700
 
 
2701
 
 
2702
    if (drizzleclient_connect(drizzle, host, user, opt_password,
 
2703
                        connect_to_schema ? create_schema_string : NULL,
 
2704
                        opt_drizzle_port,
 
2705
                        opt_drizzle_unix_port,
 
2706
                        connect_flags))
2708
2707
    {
2709
2708
      /* Connect suceeded */
2710
2709
      connect_error= 0;
2714
2713
  }
2715
2714
  if (connect_error)
2716
2715
  {
2717
 
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
2718
 
            ret, drizzle_con_error(con));
 
2716
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
 
2717
            my_progname, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
2719
2718
    exit(1);
2720
2719
  }
2721
2720