~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-09-13 01:03:01 UTC
  • mto: (1126.9.2 captain-20090915-01)
  • mto: This revision was merged to the branch mainline in revision 1133.
  • Revision ID: osullivan.padraig@gmail.com-20090913010301-tcvvezipx1124acy
Added calls to the dtrace delete begin/end probes.

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
 
99
90
using namespace std;
100
 
using namespace drizzled;
101
91
 
102
92
#ifdef HAVE_SMEM
103
93
static char *shared_memory_base_name=0;
104
94
#endif
105
95
 
 
96
extern "C"
 
97
bool get_one_option(int optid, const struct my_option *, char *argument);
 
98
 
106
99
/* Global Thread counter */
107
100
uint32_t thread_counter;
108
101
pthread_mutex_t counter_mutex;
128
121
  *user_supplied_post_statements= NULL,
129
122
  *default_engine= NULL,
130
123
  *pre_system= NULL,
131
 
  *post_system= NULL;
 
124
  *post_system= NULL,
 
125
  *opt_drizzle_unix_port= NULL;
132
126
 
133
127
const char *delimiter= "\n";
134
128
 
135
129
const char *create_schema_string= "drizzleslap";
136
130
 
137
 
static bool opt_mysql= false;
138
131
static bool opt_preserve= true;
 
132
static bool debug_info_flag= false, debug_check_flag= false;
139
133
static bool opt_only_print= false;
140
134
static bool opt_burnin= false;
141
135
static bool opt_ignore_sql_errors= false;
142
 
static bool tty_password= false,
 
136
static bool opt_compress= false, tty_password= false,
143
137
  opt_silent= false,
144
138
  auto_generate_sql_autoincrement= false,
145
139
  auto_generate_sql_guid_primary= false,
168
162
static unsigned int num_int_cols_index= 0;
169
163
static unsigned int num_char_cols_index= 0;
170
164
static unsigned int iterations;
 
165
static uint32_t my_end_arg= 0;
171
166
static uint64_t actual_queries= 0;
172
167
static uint64_t auto_actual_queries;
173
168
static uint64_t auto_generate_sql_unique_write_number;
181
176
 
182
177
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
183
178
const char *opt_csv_str;
184
 
int csv_file;
 
179
File csv_file;
185
180
 
186
181
static int get_options(int *argc,char ***argv);
187
182
static uint32_t opt_drizzle_port= 0;
323
318
  option_string *eptr;
324
319
  unsigned int x;
325
320
 
326
 
  internal::my_init();
 
321
  my_init();
327
322
 
328
323
  MY_INIT(argv[0]);
329
324
 
330
 
  internal::load_defaults("drizzle",load_default_groups,&argc,&argv);
 
325
  load_defaults("drizzle",load_default_groups,&argc,&argv);
331
326
  defaults_argv=argv;
332
327
  if (get_options(&argc,&argv))
333
328
  {
334
 
    internal::free_defaults(defaults_argv);
335
 
    internal::my_end();
 
329
    free_defaults(defaults_argv);
 
330
    my_end(0);
336
331
    exit(1);
337
332
  }
338
333
 
349
344
 
350
345
  if (argc > 2)
351
346
  {
352
 
    fprintf(stderr,"%s: Too many arguments\n",internal::my_progname);
353
 
    internal::free_defaults(defaults_argv);
354
 
    internal::my_end();
 
347
    fprintf(stderr,"%s: Too many arguments\n",my_progname);
 
348
    free_defaults(defaults_argv);
 
349
    my_end(0);
355
350
    exit(1);
356
351
  }
357
352
 
426
421
  if (shared_memory_base_name)
427
422
    free(shared_memory_base_name);
428
423
#endif
429
 
  internal::free_defaults(defaults_argv);
430
 
  internal::my_end();
 
424
  free_defaults(defaults_argv);
 
425
  my_end(my_end_arg);
431
426
 
432
427
  return 0;
433
428
}
528
523
}
529
524
 
530
525
 
531
 
static struct option my_long_options[] =
 
526
static struct my_option my_long_options[] =
532
527
{
533
528
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
534
529
   0, 0, 0, 0, 0, 0},
593
588
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
594
589
   (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
595
590
   0, 0, 0, 0, 0, 0},
 
591
  {"compress", 'C', "Use compression in server/client protocol.",
 
592
   (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
593
   0, 0, 0},
596
594
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
597
595
   (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
598
596
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
606
604
   "Generate CSV output to named file or to stdout if no file is named.",
607
605
   (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
608
606
   OPT_ARG, 0, 0, 0, 0, 0, 0},
 
607
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
 
608
    (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
 
609
    GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
610
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
 
611
    (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
609
612
  {"delayed-start", OPT_SLAP_DELAYED_START,
610
613
   "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
611
614
   (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
628
631
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
629
632
   (char**) &opt_label, (char**) &opt_label, 0,
630
633
   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
634
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
635
635
   "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
636
   (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
691
691
  {"silent", 's', "Run program in silent mode - no output.",
692
692
   (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
693
693
   0, 0, 0, 0, 0, 0},
 
694
  {"socket", 'S', "Socket file to use for connection.",
 
695
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
 
696
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
694
697
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
695
698
   "Require drizzleslap to run each specific test a certain amount of time in seconds.",
696
699
   (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
709
712
 
710
713
static void print_version(void)
711
714
{
712
 
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
 
715
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",my_progname, SLAP_VERSION,
713
716
         drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
714
717
}
715
718
 
722
725
       \nand you are welcome to modify and redistribute it under the GPL \
723
726
       license\n");
724
727
  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);
 
728
  printf("Usage: %s [OPTIONS]\n",my_progname);
 
729
  print_defaults("drizzle",load_default_groups);
727
730
  my_print_help(my_long_options);
728
731
}
729
732
 
730
 
static int get_one_option(int optid, const struct option *, char *argument)
 
733
bool get_one_option(int optid, const struct my_option *, char *argument)
731
734
{
732
735
  char *endchar= NULL;
733
736
  uint64_t temp_drizzle_port= 0;
742
745
    if (strlen(endchar) != 0)
743
746
    {
744
747
      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;
 
748
      exit(1);
746
749
    }
747
750
    /* If the port number is > 65535 it is not a valid port
748
751
       This also helps with potential data loss casting unsigned long to a
750
753
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
751
754
    {
752
755
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
753
 
      return EXIT_ARGUMENT_INVALID;
 
756
      exit(1);
754
757
    }
755
758
    else
756
759
    {
768
771
      {
769
772
        fprintf(stderr, "Memory allocation error while copying password. "
770
773
                        "Aborting.\n");
771
 
        return EXIT_OUT_OF_MEMORY;
 
774
        exit(ENOMEM);
772
775
      }
773
776
      while (*argument)
774
777
      {
1284
1287
 
1285
1288
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1286
1289
    exit(ho_error);
 
1290
  if (debug_info_flag)
 
1291
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
 
1292
  if (debug_check_flag)
 
1293
    my_end_arg= MY_CHECK_ERROR;
1287
1294
 
1288
1295
  if (!user)
1289
1296
    user= (char *)"root";
1296
1303
  {
1297
1304
    fprintf(stderr,
1298
1305
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1299
 
            internal::my_progname);
 
1306
            my_progname);
1300
1307
    exit(1);
1301
1308
  }
1302
1309
 
1305
1312
  {
1306
1313
    fprintf(stderr,
1307
1314
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1308
 
            internal::my_progname);
 
1315
            my_progname);
1309
1316
    exit(1);
1310
1317
  }
1311
1318
 
1313
1320
  {
1314
1321
    fprintf(stderr,
1315
1322
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1316
 
            internal::my_progname);
 
1323
            my_progname);
1317
1324
    exit(1);
1318
1325
  }
1319
1326
 
1333
1340
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1334
1341
      {
1335
1342
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1336
 
                internal::my_progname, opt_csv_str);
 
1343
                my_progname, opt_csv_str);
1337
1344
        exit(1);
1338
1345
      }
1339
1346
    }
1454
1461
        {
1455
1462
          fprintf(stderr,
1456
1463
                  "%s: Can't perform key test without a primary key!\n",
1457
 
                  internal::my_progname);
 
1464
                  my_progname);
1458
1465
          exit(1);
1459
1466
        }
1460
1467
 
1490
1497
        {
1491
1498
          fprintf(stderr,
1492
1499
                  "%s: Can't perform update test without a primary key!\n",
1493
 
                  internal::my_progname);
 
1500
                  my_progname);
1494
1501
          exit(1);
1495
1502
        }
1496
1503
 
1534
1541
  {
1535
1542
    if (create_string && !stat(create_string, &sbuf))
1536
1543
    {
1537
 
      int data_file;
 
1544
      File data_file;
1538
1545
      if (!S_ISREG(sbuf.st_mode))
1539
1546
      {
1540
1547
        fprintf(stderr,"%s: Create file was not a regular file\n",
1541
 
                internal::my_progname);
 
1548
                my_progname);
1542
1549
        exit(1);
1543
1550
      }
1544
1551
      if ((data_file= open(create_string, O_RDWR)) == -1)
1545
1552
      {
1546
 
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
 
1553
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1547
1554
        exit(1);
1548
1555
      }
1549
1556
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1591
1598
 
1592
1599
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1593
1600
    {
1594
 
      int data_file;
 
1601
      File data_file;
1595
1602
      if (!S_ISREG(sbuf.st_mode))
1596
1603
      {
1597
1604
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1598
 
                internal::my_progname);
 
1605
                my_progname);
1599
1606
        exit(1);
1600
1607
      }
1601
1608
      if ((data_file= open(user_supplied_query, O_RDWR)) == -1)
1602
1609
      {
1603
 
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1610
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1604
1611
        exit(1);
1605
1612
      }
1606
1613
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1638
1645
  if (user_supplied_pre_statements
1639
1646
      && !stat(user_supplied_pre_statements, &sbuf))
1640
1647
  {
1641
 
    int data_file;
 
1648
    File data_file;
1642
1649
    if (!S_ISREG(sbuf.st_mode))
1643
1650
    {
1644
1651
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1645
 
              internal::my_progname);
 
1652
              my_progname);
1646
1653
      exit(1);
1647
1654
    }
1648
1655
    if ((data_file= open(user_supplied_pre_statements, O_RDWR)) == -1)
1649
1656
    {
1650
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1657
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1651
1658
      exit(1);
1652
1659
    }
1653
1660
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1685
1692
  if (user_supplied_post_statements
1686
1693
      && !stat(user_supplied_post_statements, &sbuf))
1687
1694
  {
1688
 
    int data_file;
 
1695
    File data_file;
1689
1696
    if (!S_ISREG(sbuf.st_mode))
1690
1697
    {
1691
1698
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1692
 
              internal::my_progname);
 
1699
              my_progname);
1693
1700
      exit(1);
1694
1701
    }
1695
1702
    if ((data_file= open(user_supplied_post_statements, O_RDWR)) == -1)
1696
1703
    {
1697
 
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1704
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1698
1705
      exit(1);
1699
1706
    }
1700
1707
 
1809
1816
  {
1810
1817
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1811
1818
    {
1812
 
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
 
1819
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1813
1820
              drizzle_con_error(con));
1814
1821
      exit(1);
1815
1822
    }
1892
1899
 
1893
1900
  if (run_query(con, NULL, query, len))
1894
1901
  {
1895
 
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
 
1902
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1896
1903
            drizzle_con_error(con));
1897
1904
    exit(1);
1898
1905
  }
1916
1923
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
1917
1924
        ret != DRIZZLE_RETURN_OK)
1918
1925
    {
1919
 
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
 
1926
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1920
1927
              ret == DRIZZLE_RETURN_ERROR_CODE ?
1921
1928
              drizzle_result_error(&result) : drizzle_con_error(con));
1922
1929
      exit(1);
1931
1938
                  engine_stmt->string);
1932
1939
    if (run_query(con, NULL, query, len))
1933
1940
    {
1934
 
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
 
1941
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1935
1942
              drizzle_con_error(con));
1936
1943
      exit(1);
1937
1944
    }
1956
1963
      if (run_query(con, NULL, buffer, strlen(buffer)))
1957
1964
      {
1958
1965
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1959
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
1966
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1960
1967
        if (!opt_ignore_sql_errors)
1961
1968
          exit(1);
1962
1969
      }
1967
1974
      if (run_query(con, NULL, ptr->string, ptr->length))
1968
1975
      {
1969
1976
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1970
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
1977
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1971
1978
        if (!opt_ignore_sql_errors)
1972
1979
          exit(1);
1973
1980
      }
2000
2007
  if (run_query(con, NULL, query, len))
2001
2008
  {
2002
2009
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
2003
 
            internal::my_progname, db, drizzle_con_error(con));
 
2010
            my_progname, db, drizzle_con_error(con));
2004
2011
    exit(1);
2005
2012
  }
2006
2013
 
2019
2026
    if (run_query(con, NULL, ptr->string, ptr->length))
2020
2027
    {
2021
2028
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2022
 
              internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
2029
              my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
2023
2030
      exit(1);
2024
2031
    }
2025
2032
  }
2083
2090
        if (pthread_create(&mainthread, &attr, run_task,
2084
2091
                           (void *)con) != 0)
2085
2092
        {
2086
 
          fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
 
2093
          fprintf(stderr,"%s: Could not create thread\n", my_progname);
2087
2094
          exit(1);
2088
2095
        }
2089
2096
        thread_counter++;
2103
2110
    if (pthread_create(&mainthread, &attr, timer_thread,
2104
2111
                       (void *)&opt_timer_length) != 0)
2105
2112
    {
2106
 
      fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
 
2113
      fprintf(stderr,"%s: Could not create timer thread\n", my_progname);
2107
2114
      exit(1);
2108
2115
    }
2109
2116
  }
2244
2251
        if (run_query(&con, &result, buffer, length))
2245
2252
        {
2246
2253
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2247
 
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
 
2254
                  my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2248
2255
          exit(1);
2249
2256
        }
2250
2257
      }
2254
2261
      if (run_query(&con, &result, ptr->string, ptr->length))
2255
2262
      {
2256
2263
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2257
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
 
2264
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
2258
2265
        exit(1);
2259
2266
      }
2260
2267
    }
2575
2582
           con->real_users, /* Children used max_timing */
2576
2583
           con->avg_rows  /* Queries run */
2577
2584
           );
2578
 
  internal::my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
 
2585
  my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2579
2586
}
2580
2587
 
2581
2588
void
2696
2703
      drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
2697
2704
                          opt_password,
2698
2705
                          connect_to_schema ? create_schema_string : NULL,
2699
 
                          opt_mysql ? DRIZZLE_CON_MYSQL : DRIZZLE_CON_NONE) == NULL)
 
2706
                          DRIZZLE_CON_NONE) == NULL)
2700
2707
  {
2701
 
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
 
2708
    fprintf(stderr,"%s: Error creating drizzle object\n", my_progname);
2702
2709
    exit(1);
2703
2710
  }
2704
2711
 
2714
2721
  }
2715
2722
  if (connect_error)
2716
2723
  {
2717
 
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
 
2724
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", my_progname,
2718
2725
            ret, drizzle_con_error(con));
2719
2726
    exit(1);
2720
2727
  }