~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2010-10-28 17:12:01 UTC
  • mfrom: (1887.1.3 merge)
  • Revision ID: brian@tangent.org-20101028171201-baj6l1bnntn1s4ad
Merge in POTFILES changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
#include "stats.h"
79
79
#include "thread_context.h"
80
80
#include "conclusions.h"
81
 
#include "wakeup.h"
82
81
 
83
82
#include <signal.h>
84
83
#include <stdarg.h>
94
93
#include <string>
95
94
#include <iostream>
96
95
#include <fstream>
 
96
#include <pthread.h>
97
97
#include <drizzled/configmake.h>
98
 
#include <memory>
99
 
 
100
98
/* Added this for string translation. */
101
99
#include <drizzled/gettext.h>
102
 
 
103
 
#include <boost/thread.hpp>
104
 
#include <boost/thread/mutex.hpp>
105
 
#include <boost/thread/condition_variable.hpp>
106
100
#include <boost/program_options.hpp>
107
 
#include <boost/scoped_ptr.hpp>
108
 
#include <drizzled/atomics.h>
109
101
 
110
 
#define SLAP_NAME "drizzleslap"
111
102
#define SLAP_VERSION "1.5"
112
103
 
113
104
#define HUGE_STRING_LENGTH 8196
122
113
static char *shared_memory_base_name=0;
123
114
#endif
124
115
 
125
 
client::Wakeup master_wakeup;
 
116
/* Global Thread counter */
 
117
uint32_t thread_counter;
 
118
pthread_mutex_t counter_mutex;
 
119
pthread_cond_t count_threshhold;
 
120
uint32_t master_wakeup;
 
121
pthread_mutex_t sleeper_mutex;
 
122
pthread_cond_t sleep_threshhold;
126
123
 
127
124
/* Global Thread timer */
128
125
static bool timer_alarm= false;
129
 
boost::mutex timer_alarm_mutex;
130
 
boost::condition_variable_any timer_alarm_threshold;
 
126
pthread_mutex_t timer_alarm_mutex;
 
127
pthread_cond_t timer_alarm_threshold;
131
128
 
132
129
std::vector < std::string > primary_keys;
133
130
 
134
 
drizzled::atomic<size_t> connection_count;
135
 
drizzled::atomic<uint64_t> failed_update_for_transaction;
136
 
 
137
131
static string host, 
138
132
  opt_password, 
139
133
  user,
172
166
  num_char_cols_opt,
173
167
  num_int_cols_opt;
174
168
string opt_label;
175
 
static uint32_t opt_set_random_seed;
 
169
static unsigned int opt_set_random_seed;
176
170
 
177
171
string auto_generate_selected_columns_opt;
178
172
 
179
173
/* Yes, we do set defaults here */
180
 
static uint32_t num_int_cols= 1;
181
 
static uint32_t num_char_cols= 1;
182
 
static uint32_t num_blob_cols= 0;
183
 
static uint32_t num_blob_cols_size;
184
 
static uint32_t num_blob_cols_size_min;
185
 
static uint32_t num_int_cols_index= 0;
186
 
static uint32_t num_char_cols_index= 0;
 
174
static unsigned int num_int_cols= 1;
 
175
static unsigned int num_char_cols= 1;
 
176
static unsigned int num_blob_cols= 0;
 
177
static unsigned int num_blob_cols_size;
 
178
static unsigned int num_blob_cols_size_min;
 
179
static unsigned int num_int_cols_index= 0;
 
180
static unsigned int num_char_cols_index= 0;
187
181
static uint32_t iterations;
188
182
static uint64_t actual_queries= 0;
189
183
static uint64_t auto_actual_queries;
196
190
string create_string;
197
191
std::vector <uint32_t> concurrency;
198
192
 
 
193
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
199
194
std::string opt_csv_str;
200
195
int csv_file;
201
196
 
209
204
static Statement *create_statements= NULL;
210
205
 
211
206
static std::vector <Statement *> query_statements;
212
 
static uint32_t query_statements_count;
 
207
static unsigned int query_statements_count;
213
208
 
214
209
 
215
210
/* Prototypes */
216
 
void print_conclusions(Conclusions &con);
217
 
void print_conclusions_csv(Conclusions &con);
 
211
void print_conclusions(Conclusions *con);
 
212
void print_conclusions_csv(Conclusions *con);
218
213
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr);
219
214
uint32_t parse_comma(const char *string, std::vector <uint32_t> &range);
220
215
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm);
221
216
uint32_t parse_option(const char *origin, OptionString **stmt, char delm);
222
 
static void drop_schema(drizzle_con_st &con, const char *db);
 
217
static int drop_schema(drizzle_con_st *con, const char *db);
223
218
uint32_t get_random_string(char *buf, size_t size);
224
219
static Statement *build_table_string(void);
225
220
static Statement *build_insert_string(void);
226
221
static Statement *build_update_string(void);
227
222
static Statement * build_select_string(bool key);
228
 
static int generate_primary_key_list(drizzle_con_st &con, OptionString *engine_stmt);
229
 
static void create_schema(drizzle_con_st &con, const char *db, Statement *stmt, OptionString *engine_stmt, Stats *sptr);
230
 
static void run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit);
 
223
static int generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt);
 
224
static int create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
 
225
                         OptionString *engine_stmt, Stats *sptr);
 
226
static int run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur,
 
227
                         uint64_t limit);
 
228
extern "C" pthread_handler_t run_task(void *p);
 
229
extern "C" pthread_handler_t timer_thread(void *p);
231
230
void statement_cleanup(Statement *stmt);
232
231
void option_cleanup(OptionString *stmt);
233
 
void concurrency_loop(drizzle_con_st &con, uint32_t current, OptionString *eptr);
234
 
static void run_statements(drizzle_con_st &con, Statement *stmt);
235
 
void slap_connect(drizzle_con_st &con, bool connect_to_schema);
236
 
void slap_close(drizzle_con_st &con);
237
 
static int run_query(drizzle_con_st &con, drizzle_result_st *result, const char *query, int len);
238
 
void standard_deviation(Conclusions &con, Stats *sptr);
 
232
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr);
 
233
static int run_statements(drizzle_con_st *con, Statement *stmt);
 
234
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
 
235
void slap_close(drizzle_con_st *con);
 
236
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
 
237
void standard_deviation (Conclusions *con, Stats *sptr);
239
238
 
240
239
static const char ALPHANUMERICS[]=
241
240
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
265
264
    user_supplied_query.append(delimiter);
266
265
  }
267
266
}
268
 
 
269
 
 
270
 
static void run_task(ThreadContext *ctx)
271
 
{
272
 
  uint64_t counter= 0, queries;
273
 
  uint64_t detach_counter;
274
 
  uint32_t commit_counter;
275
 
  boost::scoped_ptr<drizzle_con_st> con_ap(new drizzle_con_st);
276
 
  drizzle_con_st &con= *con_ap.get();
277
 
  drizzle_result_st result;
278
 
  drizzle_row_t row;
279
 
  Statement *ptr;
280
 
 
281
 
  master_wakeup.wait();
282
 
 
283
 
  slap_connect(con, true);
284
 
 
285
 
  if (verbose >= 3)
286
 
    printf("connected!\n");
287
 
  queries= 0;
288
 
 
289
 
  commit_counter= 0;
290
 
  if (commit_rate)
291
 
    run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
292
 
 
293
 
limit_not_met:
294
 
  for (ptr= ctx->getStmt(), detach_counter= 0;
295
 
       ptr && ptr->getLength();
296
 
       ptr= ptr->getNext(), detach_counter++)
297
 
  {
298
 
    if (not opt_only_print && detach_rate && !(detach_counter % detach_rate))
299
 
    {
300
 
      slap_close(con);
301
 
      slap_connect(con, true);
302
 
    }
303
 
 
304
 
    /*
305
 
      We have to execute differently based on query type. This should become a function.
306
 
    */
307
 
    bool is_failed_update= false;
308
 
    if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
309
 
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
310
 
    {
311
 
      int length;
312
 
      uint32_t key_val;
313
 
      char buffer[HUGE_STRING_LENGTH];
314
 
 
315
 
      /*
316
 
        This should only happen if some sort of new engine was
317
 
        implemented that didn't properly handle UPDATEs.
318
 
 
319
 
        Just in case someone runs this under an experimental engine we don't
320
 
        want a crash so the if() is placed here.
321
 
      */
322
 
      assert(primary_keys.size());
323
 
      if (primary_keys.size())
324
 
      {
325
 
        key_val= (uint32_t)(random() % primary_keys.size());
326
 
        const char *key;
327
 
        key= primary_keys[key_val].c_str();
328
 
 
329
 
        assert(key);
330
 
 
331
 
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
332
 
                         (int)ptr->getLength(), ptr->getString(), key);
333
 
 
334
 
        if (run_query(con, &result, buffer, length))
335
 
        {
336
 
          if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
337
 
          {
338
 
            // Expand to check to see if Innodb, if so we should restart the
339
 
            // transaction.  
340
 
 
341
 
            is_failed_update= true;
342
 
            failed_update_for_transaction.fetch_and_increment();
343
 
          }
344
 
          else
345
 
          {
346
 
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
347
 
                    SLAP_NAME, (uint32_t)length, buffer, drizzle_con_error(&con));
348
 
            abort();
349
 
          }
350
 
        }
351
 
      }
352
 
    }
353
 
    else
354
 
    {
355
 
      if (run_query(con, &result, ptr->getString(), ptr->getLength()))
356
 
      {
357
 
        if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) and commit_rate)
358
 
        {
359
 
          // Expand to check to see if Innodb, if so we should restart the
360
 
          // transaction.
361
 
 
362
 
          is_failed_update= true;
363
 
          failed_update_for_transaction.fetch_and_increment();
364
 
        }
365
 
        else
366
 
        {
367
 
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
368
 
                  SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
369
 
          abort();
370
 
        }
371
 
      }
372
 
    }
373
 
 
374
 
    if (not opt_only_print and not is_failed_update)
375
 
    {
376
 
      while ((row = drizzle_row_next(&result)))
377
 
        counter++;
378
 
      drizzle_result_free(&result);
379
 
    }
380
 
    queries++;
381
 
 
382
 
    if (commit_rate && (++commit_counter == commit_rate) and not is_failed_update)
383
 
    {
384
 
      commit_counter= 0;
385
 
      run_query(con, NULL, "COMMIT", strlen("COMMIT"));
386
 
    }
387
 
 
388
 
    /* If the timer is set, and the alarm is not active then end */
389
 
    if (opt_timer_length && timer_alarm == false)
390
 
      goto end;
391
 
 
392
 
    /* If limit has been reached, and we are not in a timer_alarm just end */
393
 
    if (ctx->getLimit() && queries == ctx->getLimit() && timer_alarm == false)
394
 
      goto end;
395
 
  }
396
 
 
397
 
  if (opt_timer_length && timer_alarm == true)
398
 
    goto limit_not_met;
399
 
 
400
 
  if (ctx->getLimit() && queries < ctx->getLimit())
401
 
    goto limit_not_met;
402
 
 
403
 
 
404
 
end:
405
 
  if (commit_rate)
406
 
    run_query(con, NULL, "COMMIT", strlen("COMMIT"));
407
 
 
408
 
  slap_close(con);
409
 
 
410
 
  delete ctx;
411
 
}
412
 
 
413
267
/**
414
268
 * commandline_options is the set of all options that can only be called via the command line.
415
269
 
436
290
    po::options_description commandline_options("Options used only in command line");
437
291
    commandline_options.add_options()
438
292
      ("help,?","Display this help and exit")
439
 
      ("info","Gives information and exit")
 
293
      ("info,i","Gives information and exit")
440
294
      ("burnin",po::value<bool>(&opt_burnin)->default_value(false)->zero_tokens(),
441
295
       "Run full test case in infinite loop")
442
296
      ("ignore-sql-errors", po::value<bool>(&opt_ignore_sql_errors)->default_value(false)->zero_tokens(),
552
406
 
553
407
    std::string user_config_dir((getenv("XDG_CONFIG_HOME")? getenv("XDG_CONFIG_HOME"):"~/.config"));
554
408
 
555
 
    if (user_config_dir.compare(0, 2, "~/") == 0)
556
 
    {
557
 
      char *homedir;
558
 
      homedir= getenv("HOME");
559
 
      if (homedir != NULL)
560
 
        user_config_dir.replace(0, 1, homedir);
561
 
    }
562
 
 
563
409
    uint64_t temp_drizzle_port= 0;
564
 
    boost::scoped_ptr<drizzle_con_st> con_ap(new drizzle_con_st);
565
 
    drizzle_con_st &con= *con_ap.get();
 
410
    drizzle_con_st con;
566
411
    OptionString *eptr;
567
412
 
568
413
    // Disable allow_guessing
593
438
    po::notify(vm);
594
439
 
595
440
    if (process_options())
596
 
      abort();
 
441
      exit(1);
597
442
 
598
443
    if ( vm.count("help") || vm.count("info"))
599
444
    {
600
 
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
 
445
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
601
446
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
602
447
      puts("Copyright (C) 2008 Sun Microsystems");
603
448
      puts("This software comes with ABSOLUTELY NO WARRANTY. "
606
451
           "license\n");
607
452
      puts("Run a query multiple times against the server\n");
608
453
      cout << long_options << endl;
609
 
      abort();
 
454
      exit(0);
610
455
    }   
611
456
 
612
457
    if (vm.count("protocol"))
621
466
      else
622
467
      {
623
468
        cout << _("Error: Unknown protocol") << " '" << opt_protocol << "'" << endl;
624
 
        abort();
 
469
        exit(-1);
625
470
      }
626
471
    }
627
472
    if (vm.count("port")) 
631
476
      if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
632
477
      {
633
478
        fprintf(stderr, _("Value supplied for port is not valid.\n"));
634
 
        abort();
 
479
        exit(1);
635
480
      }
636
481
      else
637
482
      {
641
486
 
642
487
  if ( vm.count("password") )
643
488
  {
644
 
    if (not opt_password.empty())
 
489
    if (!opt_password.empty())
645
490
      opt_password.erase();
646
491
    if (password == PASSWORD_SENTINEL)
647
492
    {
662
507
 
663
508
    if ( vm.count("version") )
664
509
    {
665
 
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",SLAP_NAME, SLAP_VERSION,
 
510
      printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",internal::my_progname, SLAP_VERSION,
666
511
          drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
667
 
      abort();
 
512
      exit(0);
668
513
    }
669
514
 
670
515
    /* Seed the random number generator if we will be using it. */
671
516
    if (auto_generate_sql)
672
517
    {
673
518
      if (opt_set_random_seed == 0)
674
 
        opt_set_random_seed= (uint32_t)time(NULL);
 
519
        opt_set_random_seed= (unsigned int)time(NULL);
675
520
      srandom(opt_set_random_seed);
676
521
    }
677
522
 
678
523
    /* globals? Yes, so we only have to run strlen once */
679
524
    delimiter_length= delimiter.length();
680
525
 
681
 
    slap_connect(con, false);
 
526
    slap_connect(&con, false);
 
527
 
 
528
    pthread_mutex_init(&counter_mutex, NULL);
 
529
    pthread_cond_init(&count_threshhold, NULL);
 
530
    pthread_mutex_init(&sleeper_mutex, NULL);
 
531
    pthread_cond_init(&sleep_threshhold, NULL);
 
532
    pthread_mutex_init(&timer_alarm_mutex, NULL);
 
533
    pthread_cond_init(&timer_alarm_threshold, NULL);
 
534
 
682
535
 
683
536
    /* Main iterations loop */
684
537
burnin:
694
547
      if (concurrency.size())
695
548
      {
696
549
        for (current= &concurrency[0]; current && *current; current++)
697
 
          concurrency_loop(con, *current, eptr);
 
550
          concurrency_loop(&con, *current, eptr);
698
551
      }
699
552
      else
700
553
      {
701
554
        uint32_t infinite= 1;
702
555
        do {
703
 
          concurrency_loop(con, infinite, eptr);
 
556
          concurrency_loop(&con, infinite, eptr);
704
557
        }
705
558
        while (infinite++);
706
559
      }
707
560
 
708
 
      if (not opt_preserve)
709
 
        drop_schema(con, create_schema_string.c_str());
 
561
      if (!opt_preserve)
 
562
        drop_schema(&con, create_schema_string.c_str());
710
563
 
711
564
    } while (eptr ? (eptr= eptr->getNext()) : 0);
712
565
 
713
566
    if (opt_burnin)
714
567
      goto burnin;
715
568
 
716
 
    slap_close(con);
 
569
    pthread_mutex_destroy(&counter_mutex);
 
570
    pthread_cond_destroy(&count_threshhold);
 
571
    pthread_mutex_destroy(&sleeper_mutex);
 
572
    pthread_cond_destroy(&sleep_threshhold);
 
573
    pthread_mutex_destroy(&timer_alarm_mutex);
 
574
    pthread_cond_destroy(&timer_alarm_threshold);
 
575
 
 
576
    slap_close(&con);
717
577
 
718
578
    /* now free all the strings we created */
719
 
    if (not opt_password.empty())
 
579
    if (!opt_password.empty())
720
580
      opt_password.erase();
721
581
 
722
582
    concurrency.clear();
748
608
  return 0;
749
609
}
750
610
 
751
 
void concurrency_loop(drizzle_con_st &con, uint32_t current, OptionString *eptr)
 
611
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr)
752
612
{
753
613
  Stats *head_sptr;
754
614
  Stats *sptr;
759
619
  if (head_sptr == NULL)
760
620
  {
761
621
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
762
 
    abort();
 
622
    exit(1);
763
623
  }
764
624
 
765
625
  if (auto_actual_queries)
793
653
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
794
654
      generate_primary_key_list(con, eptr);
795
655
 
796
 
    if (not pre_system.empty())
 
656
    if (commit_rate)
 
657
      run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
658
 
 
659
    if (!pre_system.empty())
797
660
    {
798
661
      int ret= system(pre_system.c_str());
799
662
      assert(ret != -1);
800
663
    }
 
664
       
801
665
 
802
666
    /*
803
667
      Pre statements are always run after all other logic so they can
811
675
    if (post_statements)
812
676
      run_statements(con, post_statements);
813
677
 
814
 
    if (not post_system.empty())
 
678
    if (!post_system.empty())
815
679
    {
816
680
      int ret=  system(post_system.c_str());
817
681
      assert(ret !=-1);
827
691
 
828
692
  generate_stats(&conclusion, eptr, head_sptr);
829
693
 
830
 
  if (not opt_silent)
831
 
    print_conclusions(conclusion);
832
 
  if (not opt_csv_str.empty())
833
 
    print_conclusions_csv(conclusion);
 
694
  if (!opt_silent)
 
695
    print_conclusions(&conclusion);
 
696
  if (!opt_csv_str.empty())
 
697
    print_conclusions_csv(&conclusion);
834
698
 
835
699
  delete [] head_sptr;
836
700
}
837
701
 
838
702
 
839
 
uint32_t get_random_string(char *buf, size_t size)
 
703
uint
 
704
get_random_string(char *buf, size_t size)
840
705
{
841
706
  char *buf_ptr= buf;
842
707
 
856
721
build_table_string(void)
857
722
{
858
723
  char       buf[HUGE_STRING_LENGTH];
859
 
  uint32_t        col_count;
 
724
  unsigned int        col_count;
860
725
  Statement *ptr;
861
726
  string table_string;
862
727
 
882
747
 
883
748
  if (auto_generate_sql_secondary_indexes)
884
749
  {
885
 
    for (uint32_t count= 0; count < auto_generate_sql_secondary_indexes; count++)
 
750
    unsigned int count;
 
751
 
 
752
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
886
753
    {
887
754
      if (count) /* Except for the first pass we add a comma */
888
755
        table_string.append(",");
891
758
          > HUGE_STRING_LENGTH)
892
759
      {
893
760
        fprintf(stderr, "Memory Allocation error in create table\n");
894
 
        abort();
 
761
        exit(1);
895
762
      }
896
763
      table_string.append(buf);
897
764
    }
909
776
                     col_count, col_count) > HUGE_STRING_LENGTH)
910
777
        {
911
778
          fprintf(stderr, "Memory Allocation error in create table\n");
912
 
          abort();
 
779
          exit(1);
913
780
        }
914
781
      }
915
782
      else
918
785
            > HUGE_STRING_LENGTH)
919
786
        {
920
787
          fprintf(stderr, "Memory Allocation error in create table\n");
921
 
          abort();
 
788
          exit(1);
922
789
        }
923
790
      }
924
791
      table_string.append(buf);
937
804
                     col_count, col_count) > HUGE_STRING_LENGTH)
938
805
        {
939
806
          fprintf(stderr, "Memory Allocation error in creating table\n");
940
 
          abort();
 
807
          exit(1);
941
808
        }
942
809
      }
943
810
      else
946
813
                     col_count) > HUGE_STRING_LENGTH)
947
814
        {
948
815
          fprintf(stderr, "Memory Allocation error in creating table\n");
949
 
          abort();
 
816
          exit(1);
950
817
        }
951
818
      }
952
819
      table_string.append(buf);
962
829
                   col_count) > HUGE_STRING_LENGTH)
963
830
      {
964
831
        fprintf(stderr, "Memory Allocation error in creating table\n");
965
 
        abort();
 
832
        exit(1);
966
833
      }
967
834
      table_string.append(buf);
968
835
 
976
843
  if (ptr->getString()==NULL)
977
844
  {
978
845
    fprintf(stderr, "Memory Allocation error in creating table\n");
979
 
    abort();
 
846
    exit(1);
980
847
  }
981
848
  ptr->setType(CREATE_TABLE_TYPE);
982
849
  strcpy(ptr->getString(), table_string.c_str());
993
860
build_update_string(void)
994
861
{
995
862
  char       buf[HUGE_STRING_LENGTH];
996
 
  uint32_t        col_count;
 
863
  unsigned int        col_count;
997
864
  Statement *ptr;
998
865
  string update_string;
999
866
 
1008
875
                   random()) > HUGE_STRING_LENGTH)
1009
876
      {
1010
877
        fprintf(stderr, "Memory Allocation error in creating update\n");
1011
 
        abort();
 
878
        exit(1);
1012
879
      }
1013
880
      update_string.append(buf);
1014
881
 
1027
894
          > HUGE_STRING_LENGTH)
1028
895
      {
1029
896
        fprintf(stderr, "Memory Allocation error in creating update\n");
1030
 
        abort();
 
897
        exit(1);
1031
898
      }
1032
899
      update_string.append(buf);
1033
900
 
1045
912
  if (ptr->getString() == NULL)
1046
913
  {
1047
914
    fprintf(stderr, "Memory Allocation error in creating update\n");
1048
 
    abort();
 
915
    exit(1);
1049
916
  }
1050
917
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1051
918
    ptr->setType(UPDATE_TYPE_REQUIRES_PREFIX);
1066
933
build_insert_string(void)
1067
934
{
1068
935
  char       buf[HUGE_STRING_LENGTH];
1069
 
  uint32_t        col_count;
 
936
  unsigned int        col_count;
1070
937
  Statement *ptr;
1071
938
  string insert_string;
1072
939
 
1092
959
 
1093
960
  if (auto_generate_sql_secondary_indexes)
1094
961
  {
1095
 
    uint32_t count;
 
962
    unsigned int count;
1096
963
 
1097
964
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1098
965
    {
1112
979
      if (snprintf(buf, HUGE_STRING_LENGTH, "%ld", random()) > HUGE_STRING_LENGTH)
1113
980
      {
1114
981
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1115
 
        abort();
 
982
        exit(1);
1116
983
      }
1117
984
      insert_string.append(buf);
1118
985
 
1140
1007
 
1141
1008
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1142
1009
    {
1143
 
      uint32_t buf_len;
1144
 
      uint32_t size;
1145
 
      uint32_t difference= num_blob_cols_size - num_blob_cols_size_min;
 
1010
      unsigned int buf_len;
 
1011
      unsigned int size;
 
1012
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1146
1013
 
1147
1014
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1148
1015
        num_blob_cols_size;
1165
1032
  if (ptr->getString()==NULL)
1166
1033
  {
1167
1034
    fprintf(stderr, "Memory Allocation error in creating select\n");
1168
 
    abort();
 
1035
    exit(1);
1169
1036
  }
1170
1037
  ptr->setType(INSERT_TYPE);
1171
1038
  strcpy(ptr->getString(), insert_string.c_str());
1183
1050
build_select_string(bool key)
1184
1051
{
1185
1052
  char       buf[HUGE_STRING_LENGTH];
1186
 
  uint32_t        col_count;
 
1053
  unsigned int        col_count;
1187
1054
  Statement *ptr;
1188
1055
  string query_string;
1189
1056
 
1190
1057
  query_string.reserve(HUGE_STRING_LENGTH);
1191
1058
 
1192
1059
  query_string.append("SELECT ", 7);
1193
 
  if (not auto_generate_selected_columns_opt.empty())
 
1060
  if (!auto_generate_selected_columns_opt.empty())
1194
1061
  {
1195
1062
    query_string.append(auto_generate_selected_columns_opt.c_str());
1196
1063
  }
1202
1069
          > HUGE_STRING_LENGTH)
1203
1070
      {
1204
1071
        fprintf(stderr, "Memory Allocation error in creating select\n");
1205
 
        abort();
 
1072
        exit(1);
1206
1073
      }
1207
1074
      query_string.append(buf);
1208
1075
 
1216
1083
          > HUGE_STRING_LENGTH)
1217
1084
      {
1218
1085
        fprintf(stderr, "Memory Allocation error in creating select\n");
1219
 
        abort();
 
1086
        exit(1);
1220
1087
      }
1221
1088
      query_string.append(buf);
1222
1089
 
1230
1097
          > HUGE_STRING_LENGTH)
1231
1098
      {
1232
1099
        fprintf(stderr, "Memory Allocation error in creating select\n");
1233
 
        abort();
 
1100
        exit(1);
1234
1101
      }
1235
1102
      query_string.append(buf);
1236
1103
 
1249
1116
  if (ptr->getString() == NULL)
1250
1117
  {
1251
1118
    fprintf(stderr, "Memory Allocation error in creating select\n");
1252
 
    abort();
 
1119
    exit(1);
1253
1120
  }
1254
1121
  if ((key) &&
1255
1122
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1265
1132
{
1266
1133
  struct stat sbuf;
1267
1134
  OptionString *sql_type;
1268
 
  uint32_t sql_type_count= 0;
 
1135
  unsigned int sql_type_count= 0;
1269
1136
  ssize_t bytes_read= 0;
1270
1137
  
1271
1138
  if (user.empty())
1274
1141
  verbose= opt_verbose.length();
1275
1142
 
1276
1143
  /* If something is created we clean it up, otherwise we leave schemas alone */
1277
 
  if ( (not create_string.empty()) || auto_generate_sql)
 
1144
  if ( (!create_string.empty()) || auto_generate_sql)
1278
1145
    opt_preserve= false;
1279
1146
 
1280
 
  if (auto_generate_sql && (not create_string.empty() || !user_supplied_query.empty()))
 
1147
  if (auto_generate_sql && (!create_string.empty() || !user_supplied_query.empty()))
1281
1148
  {
1282
1149
    fprintf(stderr,
1283
1150
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1284
 
            SLAP_NAME);
1285
 
    abort();
 
1151
            internal::my_progname);
 
1152
    exit(1);
1286
1153
  }
1287
1154
 
1288
1155
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1290
1157
  {
1291
1158
    fprintf(stderr,
1292
1159
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1293
 
            SLAP_NAME);
1294
 
    abort();
 
1160
            internal::my_progname);
 
1161
    exit(1);
1295
1162
  }
1296
1163
 
1297
1164
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1298
1165
  {
1299
1166
    fprintf(stderr,
1300
1167
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1301
 
            SLAP_NAME);
1302
 
    abort();
 
1168
            internal::my_progname);
 
1169
    exit(1);
1303
1170
  }
1304
1171
 
1305
 
  parse_comma(not concurrency_str.empty() ? concurrency_str.c_str() : "1", concurrency);
 
1172
  parse_comma(!concurrency_str.empty() ? concurrency_str.c_str() : "1", concurrency);
1306
1173
 
1307
 
  if (not opt_csv_str.empty())
 
1174
  if (!opt_csv_str.empty())
1308
1175
  {
1309
1176
    opt_silent= true;
1310
1177
 
1318
1185
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1319
1186
      {
1320
1187
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1321
 
                SLAP_NAME, opt_csv_str.c_str());
1322
 
        abort();
 
1188
                internal::my_progname, opt_csv_str.c_str());
 
1189
        exit(1);
1323
1190
      }
1324
1191
    }
1325
1192
  }
1327
1194
  if (opt_only_print)
1328
1195
    opt_silent= true;
1329
1196
 
1330
 
  if (not num_int_cols_opt.empty())
 
1197
  if (!num_int_cols_opt.empty())
1331
1198
  {
1332
1199
    OptionString *str;
1333
1200
    parse_option(num_int_cols_opt.c_str(), &str, ',');
1337
1204
    option_cleanup(str);
1338
1205
  }
1339
1206
 
1340
 
  if (not num_char_cols_opt.empty())
 
1207
  if (!num_char_cols_opt.empty())
1341
1208
  {
1342
1209
    OptionString *str;
1343
1210
    parse_option(num_char_cols_opt.c_str(), &str, ',');
1349
1216
    option_cleanup(str);
1350
1217
  }
1351
1218
 
1352
 
  if (not num_blob_cols_opt.empty())
 
1219
  if (!num_blob_cols_opt.empty())
1353
1220
  {
1354
1221
    OptionString *str;
1355
1222
    parse_option(num_blob_cols_opt.c_str(), &str, ',');
1433
1300
        {
1434
1301
          fprintf(stderr,
1435
1302
                  "%s: Can't perform key test without a primary key!\n",
1436
 
                  SLAP_NAME);
1437
 
          abort();
 
1303
                  internal::my_progname);
 
1304
          exit(1);
1438
1305
        }
1439
1306
 
1440
1307
        query_statements[sql_type_count]= build_select_string(true);
1469
1336
        {
1470
1337
          fprintf(stderr,
1471
1338
                  "%s: Can't perform update test without a primary key!\n",
1472
 
                  SLAP_NAME);
1473
 
          abort();
 
1339
                  internal::my_progname);
 
1340
          exit(1);
1474
1341
        }
1475
1342
 
1476
1343
        query_statements[sql_type_count]= build_update_string();
1511
1378
  }
1512
1379
  else
1513
1380
  {
1514
 
    if (not create_string.empty() && !stat(create_string.c_str(), &sbuf))
 
1381
    if (!create_string.empty() && !stat(create_string.c_str(), &sbuf))
1515
1382
    {
1516
1383
      int data_file;
1517
1384
      std::vector<char> tmp_string;
1518
 
      if (not S_ISREG(sbuf.st_mode))
 
1385
      if (!S_ISREG(sbuf.st_mode))
1519
1386
      {
1520
1387
        fprintf(stderr,"%s: Create file was not a regular file\n",
1521
 
                SLAP_NAME);
1522
 
        abort();
 
1388
                internal::my_progname);
 
1389
        exit(1);
1523
1390
      }
1524
1391
      if ((data_file= open(create_string.c_str(), O_RDWR)) == -1)
1525
1392
      {
1526
 
        fprintf(stderr,"%s: Could not open create file\n", SLAP_NAME);
1527
 
        abort();
 
1393
        fprintf(stderr,"%s: Could not open create file\n", internal::my_progname);
 
1394
        exit(1);
1528
1395
      }
1529
1396
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1530
1397
      {
1531
1398
        fprintf(stderr, "Request for more memory than architecture supports\n");
1532
 
        abort();
 
1399
        exit(1);
1533
1400
      }
1534
1401
      tmp_string.resize(sbuf.st_size + 1);
1535
1402
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1541
1408
      }
1542
1409
      parse_delimiter(&tmp_string[0], &create_statements, delimiter[0]);
1543
1410
    }
1544
 
    else if (not create_string.empty())
 
1411
    else if (!create_string.empty())
1545
1412
    {
1546
1413
      parse_delimiter(create_string.c_str(), &create_statements, delimiter[0]);
1547
1414
    }
1548
1415
 
1549
1416
    /* Set this up till we fully support options on user generated queries */
1550
 
    if (not user_supplied_query.empty())
 
1417
    if (!user_supplied_query.empty())
1551
1418
    {
1552
1419
      query_statements_count=
1553
1420
        parse_option("default", &query_options, ',');
1555
1422
      query_statements.resize(query_statements_count);
1556
1423
    }
1557
1424
 
1558
 
    if (not user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
 
1425
    if (!user_supplied_query.empty() && !stat(user_supplied_query.c_str(), &sbuf))
1559
1426
    {
1560
1427
      int data_file;
1561
1428
      std::vector<char> tmp_string;
1562
1429
 
1563
 
      if (not S_ISREG(sbuf.st_mode))
 
1430
      if (!S_ISREG(sbuf.st_mode))
1564
1431
      {
1565
1432
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1566
 
                SLAP_NAME);
1567
 
        abort();
 
1433
                internal::my_progname);
 
1434
        exit(1);
1568
1435
      }
1569
1436
      if ((data_file= open(user_supplied_query.c_str(), O_RDWR)) == -1)
1570
1437
      {
1571
 
        fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1572
 
        abort();
 
1438
        fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1439
        exit(1);
1573
1440
      }
1574
1441
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1575
1442
      {
1576
1443
        fprintf(stderr, "Request for more memory than architecture supports\n");
1577
 
        abort();
 
1444
        exit(1);
1578
1445
      }
1579
1446
      tmp_string.resize((size_t)(sbuf.st_size + 1));
1580
1447
      bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1584
1451
      {
1585
1452
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1586
1453
      }
1587
 
      if (not user_supplied_query.empty())
 
1454
      if (!user_supplied_query.empty())
1588
1455
        actual_queries= parse_delimiter(&tmp_string[0], &query_statements[0],
1589
1456
                                        delimiter[0]);
1590
1457
    }
1591
 
    else if (not user_supplied_query.empty())
 
1458
    else if (!user_supplied_query.empty())
1592
1459
    {
1593
1460
      actual_queries= parse_delimiter(user_supplied_query.c_str(), &query_statements[0],
1594
1461
                                      delimiter[0]);
1595
1462
    }
1596
1463
  }
1597
1464
 
1598
 
  if (not user_supplied_pre_statements.empty()
 
1465
  if (!user_supplied_pre_statements.empty()
1599
1466
      && !stat(user_supplied_pre_statements.c_str(), &sbuf))
1600
1467
  {
1601
1468
    int data_file;
1602
1469
    std::vector<char> tmp_string;
1603
1470
 
1604
 
    if (not S_ISREG(sbuf.st_mode))
 
1471
    if (!S_ISREG(sbuf.st_mode))
1605
1472
    {
1606
1473
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1607
 
              SLAP_NAME);
1608
 
      abort();
 
1474
              internal::my_progname);
 
1475
      exit(1);
1609
1476
    }
1610
1477
    if ((data_file= open(user_supplied_pre_statements.c_str(), O_RDWR)) == -1)
1611
1478
    {
1612
 
      fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1613
 
      abort();
 
1479
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1480
      exit(1);
1614
1481
    }
1615
1482
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1616
1483
    {
1617
1484
      fprintf(stderr, "Request for more memory than architecture supports\n");
1618
 
      abort();
 
1485
      exit(1);
1619
1486
    }
1620
1487
    tmp_string.resize((size_t)(sbuf.st_size + 1));
1621
1488
    bytes_read= read(data_file, (unsigned char*) &tmp_string[0],
1625
1492
    {
1626
1493
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1627
1494
    }
1628
 
    if (not user_supplied_pre_statements.empty())
 
1495
    if (!user_supplied_pre_statements.empty())
1629
1496
      (void)parse_delimiter(&tmp_string[0], &pre_statements,
1630
1497
                            delimiter[0]);
1631
1498
  }
1632
 
  else if (not user_supplied_pre_statements.empty())
 
1499
  else if (!user_supplied_pre_statements.empty())
1633
1500
  {
1634
1501
    (void)parse_delimiter(user_supplied_pre_statements.c_str(),
1635
1502
                          &pre_statements,
1636
1503
                          delimiter[0]);
1637
1504
  }
1638
1505
 
1639
 
  if (not user_supplied_post_statements.empty()
 
1506
  if (!user_supplied_post_statements.empty()
1640
1507
      && !stat(user_supplied_post_statements.c_str(), &sbuf))
1641
1508
  {
1642
1509
    int data_file;
1643
1510
    std::vector<char> tmp_string;
1644
1511
 
1645
 
    if (not S_ISREG(sbuf.st_mode))
 
1512
    if (!S_ISREG(sbuf.st_mode))
1646
1513
    {
1647
1514
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1648
 
              SLAP_NAME);
1649
 
      abort();
 
1515
              internal::my_progname);
 
1516
      exit(1);
1650
1517
    }
1651
1518
    if ((data_file= open(user_supplied_post_statements.c_str(), O_RDWR)) == -1)
1652
1519
    {
1653
 
      fprintf(stderr,"%s: Could not open query supplied file\n", SLAP_NAME);
1654
 
      abort();
 
1520
      fprintf(stderr,"%s: Could not open query supplied file\n", internal::my_progname);
 
1521
      exit(1);
1655
1522
    }
1656
1523
 
1657
1524
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
1658
1525
    {
1659
1526
      fprintf(stderr, "Request for more memory than architecture supports\n");
1660
 
      abort();
 
1527
      exit(1);
1661
1528
    }
1662
1529
    tmp_string.resize((size_t)(sbuf.st_size + 1));
1663
1530
 
1668
1535
    {
1669
1536
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
1670
1537
    }
1671
 
    if (not user_supplied_post_statements.empty())
 
1538
    if (!user_supplied_post_statements.empty())
1672
1539
      (void)parse_delimiter(&tmp_string[0], &post_statements,
1673
1540
                            delimiter[0]);
1674
1541
  }
1675
 
  else if (not user_supplied_post_statements.empty())
 
1542
  else if (!user_supplied_post_statements.empty())
1676
1543
  {
1677
1544
    (void)parse_delimiter(user_supplied_post_statements.c_str(), &post_statements,
1678
1545
                          delimiter[0]);
1681
1548
  if (verbose >= 2)
1682
1549
    printf("Parsing engines to use.\n");
1683
1550
 
1684
 
  if (not default_engine.empty())
 
1551
  if (!default_engine.empty())
1685
1552
    parse_option(default_engine.c_str(), &engine_options, ',');
1686
1553
 
1687
1554
  if (tty_password)
1690
1557
}
1691
1558
 
1692
1559
 
1693
 
static int run_query(drizzle_con_st &con, drizzle_result_st *result,
 
1560
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
1694
1561
                     const char *query, int len)
1695
1562
{
1696
1563
  drizzle_return_t ret;
1698
1565
 
1699
1566
  if (opt_only_print)
1700
1567
  {
1701
 
    printf("/* CON: %" PRIu64 " */ %.*s;\n",
1702
 
           (uint64_t)drizzle_context(drizzle_con_drizzle(&con)),
1703
 
           len, query);
 
1568
    printf("%.*s;\n", len, query);
1704
1569
    return 0;
1705
1570
  }
1706
1571
 
1710
1575
  if (result == NULL)
1711
1576
    result= &result_buffer;
1712
1577
 
1713
 
  result= drizzle_query(&con, result, query, len, &ret);
 
1578
  result= drizzle_query(con, result, query, len, &ret);
1714
1579
 
1715
1580
  if (ret == DRIZZLE_RETURN_OK)
1716
1581
    ret= drizzle_result_buffer(result);
1723
1588
 
1724
1589
 
1725
1590
static int
1726
 
generate_primary_key_list(drizzle_con_st &con, OptionString *engine_stmt)
 
1591
generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt)
1727
1592
{
1728
1593
  drizzle_result_st result;
1729
1594
  drizzle_row_t row;
1744
1609
  {
1745
1610
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1746
1611
    {
1747
 
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", SLAP_NAME,
1748
 
              drizzle_con_error(&con));
1749
 
      abort();
 
1612
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", internal::my_progname,
 
1613
              drizzle_con_error(con));
 
1614
      exit(1);
1750
1615
    }
1751
1616
 
1752
1617
    uint64_t num_rows_ret= drizzle_result_row_count(&result);
1753
1618
    if (num_rows_ret > SIZE_MAX)
1754
1619
    {
1755
1620
      fprintf(stderr, "More primary keys than than architecture supports\n");
1756
 
      abort();
 
1621
      exit(1);
1757
1622
    }
1758
1623
    size_t primary_keys_number_of;
1759
1624
    primary_keys_number_of= (size_t)num_rows_ret;
1778
1643
  return(0);
1779
1644
}
1780
1645
 
1781
 
static void create_schema(drizzle_con_st &con, const char *db, Statement *stmt, OptionString *engine_stmt, Stats *sptr)
 
1646
static int
 
1647
create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
 
1648
              OptionString *engine_stmt, Stats *sptr)
1782
1649
{
1783
1650
  char query[HUGE_STRING_LENGTH];
1784
1651
  Statement *ptr;
1785
1652
  Statement *after_create;
1786
1653
  int len;
 
1654
  uint64_t count;
1787
1655
  struct timeval start_time, end_time;
1788
1656
 
1789
1657
 
1796
1664
 
1797
1665
  if (run_query(con, NULL, query, len))
1798
1666
  {
1799
 
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", SLAP_NAME, db,
1800
 
            drizzle_con_error(&con));
1801
 
    abort();
 
1667
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", internal::my_progname, db,
 
1668
            drizzle_con_error(con));
 
1669
    exit(1);
1802
1670
  }
1803
1671
  else
1804
1672
  {
1807
1675
 
1808
1676
  if (opt_only_print)
1809
1677
  {
1810
 
    printf("/* CON: %" PRIu64 " */ use %s;\n",
1811
 
           (uint64_t)drizzle_context(drizzle_con_drizzle(&con)),
1812
 
           db);
 
1678
    printf("use %s;\n", db);
1813
1679
  }
1814
1680
  else
1815
1681
  {
1819
1685
    if (verbose >= 3)
1820
1686
      printf("%s;\n", query);
1821
1687
 
1822
 
    if (drizzle_select_db(&con,  &result, db, &ret) == NULL ||
 
1688
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
1823
1689
        ret != DRIZZLE_RETURN_OK)
1824
1690
    {
1825
 
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",SLAP_NAME, db,
 
1691
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",internal::my_progname, db,
1826
1692
              ret == DRIZZLE_RETURN_ERROR_CODE ?
1827
 
              drizzle_result_error(&result) : drizzle_con_error(&con));
1828
 
      abort();
 
1693
              drizzle_result_error(&result) : drizzle_con_error(con));
 
1694
      exit(1);
1829
1695
    }
1830
1696
    drizzle_result_free(&result);
1831
1697
    sptr->setCreateCount(sptr->getCreateCount()+1);
1837
1703
                  engine_stmt->getString());
1838
1704
    if (run_query(con, NULL, query, len))
1839
1705
    {
1840
 
      fprintf(stderr,"%s: Cannot set default engine: %s\n", SLAP_NAME,
1841
 
              drizzle_con_error(&con));
1842
 
      abort();
 
1706
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
 
1707
              drizzle_con_error(con));
 
1708
      exit(1);
1843
1709
    }
1844
1710
    sptr->setCreateCount(sptr->getCreateCount()+1);
1845
1711
  }
1846
1712
 
1847
 
  uint64_t count= 0;
 
1713
  count= 0;
1848
1714
  after_create= stmt;
1849
1715
 
1850
1716
limit_not_met:
1862
1728
      if (run_query(con, NULL, buffer, strlen(buffer)))
1863
1729
      {
1864
1730
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1865
 
                SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1866
 
        if (not opt_ignore_sql_errors)
1867
 
          abort();
 
1731
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
 
1732
        if (!opt_ignore_sql_errors)
 
1733
          exit(1);
1868
1734
      }
1869
1735
      sptr->setCreateCount(sptr->getCreateCount()+1);
1870
1736
    }
1873
1739
      if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1874
1740
      {
1875
1741
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1876
 
                SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1877
 
        if (not opt_ignore_sql_errors)
1878
 
          abort();
 
1742
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
 
1743
        if (!opt_ignore_sql_errors)
 
1744
          exit(1);
1879
1745
      }
1880
1746
      sptr->setCreateCount(sptr->getCreateCount()+1);
1881
1747
    }
1891
1757
  gettimeofday(&end_time, NULL);
1892
1758
 
1893
1759
  sptr->setCreateTiming(timedif(end_time, start_time));
 
1760
 
 
1761
  return(0);
1894
1762
}
1895
1763
 
1896
 
static void drop_schema(drizzle_con_st &con, const char *db)
 
1764
static int
 
1765
drop_schema(drizzle_con_st *con, const char *db)
1897
1766
{
1898
1767
  char query[HUGE_STRING_LENGTH];
1899
1768
  int len;
1903
1772
  if (run_query(con, NULL, query, len))
1904
1773
  {
1905
1774
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1906
 
            SLAP_NAME, db, drizzle_con_error(&con));
1907
 
    abort();
 
1775
            internal::my_progname, db, drizzle_con_error(con));
 
1776
    exit(1);
1908
1777
  }
 
1778
 
 
1779
 
 
1780
 
 
1781
  return(0);
1909
1782
}
1910
1783
 
1911
 
static void run_statements(drizzle_con_st &con, Statement *stmt)
 
1784
static int
 
1785
run_statements(drizzle_con_st *con, Statement *stmt)
1912
1786
{
1913
 
  for (Statement *ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
 
1787
  Statement *ptr;
 
1788
 
 
1789
  for (ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
1914
1790
  {
1915
1791
    if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1916
1792
    {
1917
1793
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1918
 
              SLAP_NAME, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
1919
 
      abort();
 
1794
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
 
1795
      exit(1);
1920
1796
    }
1921
1797
  }
 
1798
 
 
1799
  return(0);
1922
1800
}
1923
1801
 
1924
 
 
1925
 
static void timer_thread()
 
1802
static int
 
1803
run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
1926
1804
{
 
1805
  uint32_t y;
 
1806
  unsigned int real_concurrency;
 
1807
  struct timeval start_time, end_time;
 
1808
  OptionString *sql_type;
 
1809
  pthread_t mainthread;            /* Thread descriptor */
 
1810
  pthread_attr_t attr;          /* Thread attributes */
 
1811
 
 
1812
 
 
1813
  pthread_attr_init(&attr);
 
1814
  pthread_attr_setdetachstate(&attr,
 
1815
                              PTHREAD_CREATE_DETACHED);
 
1816
 
 
1817
  pthread_mutex_lock(&counter_mutex);
 
1818
  thread_counter= 0;
 
1819
 
 
1820
  pthread_mutex_lock(&sleeper_mutex);
 
1821
  master_wakeup= 1;
 
1822
  pthread_mutex_unlock(&sleeper_mutex);
 
1823
 
 
1824
  real_concurrency= 0;
 
1825
 
 
1826
  for (y= 0, sql_type= query_options;
 
1827
       y < query_statements_count;
 
1828
       y++, sql_type= sql_type->getNext())
 
1829
  {
 
1830
    unsigned int options_loop= 1;
 
1831
 
 
1832
    if (sql_type->getOption())
 
1833
    {
 
1834
      options_loop= strtol(sql_type->getOption(),
 
1835
                           (char **)NULL, 10);
 
1836
      options_loop= options_loop ? options_loop : 1;
 
1837
    }
 
1838
 
 
1839
    while (options_loop--)
 
1840
    {
 
1841
      for (uint32_t x= 0; x < concur; x++)
 
1842
      {
 
1843
        ThreadContext *con;
 
1844
        con= new ThreadContext;
 
1845
        if (con == NULL)
 
1846
        {
 
1847
          fprintf(stderr, "Memory Allocation error in scheduler\n");
 
1848
          exit(1);
 
1849
        }
 
1850
        con->setStmt(stmts[y]);
 
1851
        con->setLimit(limit);
 
1852
 
 
1853
        real_concurrency++;
 
1854
        /* now you create the thread */
 
1855
        if (pthread_create(&mainthread, &attr, run_task,
 
1856
                           (void *)con) != 0)
 
1857
        {
 
1858
          fprintf(stderr,"%s: Could not create thread\n", internal::my_progname);
 
1859
          exit(1);
 
1860
        }
 
1861
        thread_counter++;
 
1862
      }
 
1863
    }
 
1864
  }
 
1865
 
1927
1866
  /*
1928
 
    We lock around the initial call in case were we in a loop. This
1929
 
    also keeps the value properly syncronized across call threads.
 
1867
    The timer_thread belongs to all threads so it too obeys the wakeup
 
1868
    call that run tasks obey.
1930
1869
  */
1931
 
  master_wakeup.wait();
1932
 
 
1933
 
  {
1934
 
    boost::mutex::scoped_lock scopedLock(timer_alarm_mutex);
1935
 
 
1936
 
    boost::xtime xt; 
1937
 
    xtime_get(&xt, boost::TIME_UTC); 
1938
 
    xt.sec += opt_timer_length; 
1939
 
 
1940
 
    (void)timer_alarm_threshold.timed_wait(scopedLock, xt);
1941
 
  }
1942
 
 
1943
 
  {
1944
 
    boost::mutex::scoped_lock scopedLock(timer_alarm_mutex);
1945
 
    timer_alarm= false;
1946
 
  }
1947
 
}
1948
 
 
1949
 
typedef boost::shared_ptr<boost::thread> Thread;
1950
 
typedef std::vector <Thread> Threads;
1951
 
static void run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
1952
 
{
1953
 
  uint32_t real_concurrency;
1954
 
  struct timeval start_time, end_time;
1955
 
 
1956
 
  Threads threads;
1957
 
 
1958
 
  {
1959
 
    OptionString *sql_type;
1960
 
 
1961
 
    master_wakeup.reset();
1962
 
 
1963
 
    real_concurrency= 0;
1964
 
 
1965
 
    uint32_t y;
1966
 
    for (y= 0, sql_type= query_options;
1967
 
         y < query_statements_count;
1968
 
         y++, sql_type= sql_type->getNext())
1969
 
    {
1970
 
      uint32_t options_loop= 1;
1971
 
 
1972
 
      if (sql_type->getOption())
1973
 
      {
1974
 
        options_loop= strtol(sql_type->getOption(),
1975
 
                             (char **)NULL, 10);
1976
 
        options_loop= options_loop ? options_loop : 1;
1977
 
      }
1978
 
 
1979
 
      while (options_loop--)
1980
 
      {
1981
 
        for (uint32_t x= 0; x < concur; x++)
1982
 
        {
1983
 
          ThreadContext *con;
1984
 
          con= new ThreadContext;
1985
 
          if (con == NULL)
1986
 
          {
1987
 
            fprintf(stderr, "Memory Allocation error in scheduler\n");
1988
 
            abort();
1989
 
          }
1990
 
          con->setStmt(stmts[y]);
1991
 
          con->setLimit(limit);
1992
 
 
1993
 
          real_concurrency++;
1994
 
 
1995
 
          /* now you create the thread */
1996
 
          Thread thread;
1997
 
          thread= Thread(new boost::thread(boost::bind(&run_task, con)));
1998
 
          threads.push_back(thread);
1999
 
 
2000
 
        }
2001
 
      }
2002
 
    }
2003
 
 
2004
 
    /*
2005
 
      The timer_thread belongs to all threads so it too obeys the wakeup
2006
 
      call that run tasks obey.
2007
 
    */
2008
 
    if (opt_timer_length)
2009
 
    {
2010
 
      {
2011
 
        boost::mutex::scoped_lock alarmLock(timer_alarm_mutex);
2012
 
        timer_alarm= true;
2013
 
      }
2014
 
 
2015
 
      Thread thread;
2016
 
      thread= Thread(new boost::thread(&timer_thread));
2017
 
      threads.push_back(thread);
2018
 
    }
2019
 
  }
2020
 
 
2021
 
  master_wakeup.start();
 
1870
  if (opt_timer_length)
 
1871
  {
 
1872
    pthread_mutex_lock(&timer_alarm_mutex);
 
1873
    timer_alarm= true;
 
1874
    pthread_mutex_unlock(&timer_alarm_mutex);
 
1875
 
 
1876
    if (pthread_create(&mainthread, &attr, timer_thread,
 
1877
                       (void *)&opt_timer_length) != 0)
 
1878
    {
 
1879
      fprintf(stderr,"%s: Could not create timer thread\n", internal::my_progname);
 
1880
      exit(1);
 
1881
    }
 
1882
  }
 
1883
 
 
1884
  pthread_mutex_unlock(&counter_mutex);
 
1885
  pthread_attr_destroy(&attr);
 
1886
 
 
1887
  pthread_mutex_lock(&sleeper_mutex);
 
1888
  master_wakeup= 0;
 
1889
  pthread_mutex_unlock(&sleeper_mutex);
 
1890
  pthread_cond_broadcast(&sleep_threshhold);
2022
1891
 
2023
1892
  gettimeofday(&start_time, NULL);
2024
1893
 
2025
1894
  /*
2026
1895
    We loop until we know that all children have cleaned up.
2027
1896
  */
2028
 
  for (Threads::iterator iter= threads.begin(); iter != threads.end(); iter++)
 
1897
  pthread_mutex_lock(&counter_mutex);
 
1898
  while (thread_counter)
2029
1899
  {
2030
 
    (*iter)->join();
 
1900
    struct timespec abstime;
 
1901
 
 
1902
    set_timespec(abstime, 3);
 
1903
    pthread_cond_timedwait(&count_threshhold, &counter_mutex, &abstime);
2031
1904
  }
 
1905
  pthread_mutex_unlock(&counter_mutex);
2032
1906
 
2033
1907
  gettimeofday(&end_time, NULL);
2034
1908
 
 
1909
 
2035
1910
  sptr->setTiming(timedif(end_time, start_time));
2036
1911
  sptr->setUsers(concur);
2037
1912
  sptr->setRealUsers(real_concurrency);
2038
1913
  sptr->setRows(limit);
 
1914
 
 
1915
  return(0);
 
1916
}
 
1917
 
 
1918
 
 
1919
pthread_handler_t timer_thread(void *p)
 
1920
{
 
1921
  uint32_t *timer_length= (uint32_t *)p;
 
1922
  struct timespec abstime;
 
1923
 
 
1924
 
 
1925
  /*
 
1926
    We lock around the initial call in case were we in a loop. This
 
1927
    also keeps the value properly syncronized across call threads.
 
1928
  */
 
1929
  pthread_mutex_lock(&sleeper_mutex);
 
1930
  while (master_wakeup)
 
1931
  {
 
1932
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
 
1933
  }
 
1934
  pthread_mutex_unlock(&sleeper_mutex);
 
1935
 
 
1936
  set_timespec(abstime, *timer_length);
 
1937
 
 
1938
  pthread_mutex_lock(&timer_alarm_mutex);
 
1939
  pthread_cond_timedwait(&timer_alarm_threshold, &timer_alarm_mutex, &abstime);
 
1940
  pthread_mutex_unlock(&timer_alarm_mutex);
 
1941
 
 
1942
  pthread_mutex_lock(&timer_alarm_mutex);
 
1943
  timer_alarm= false;
 
1944
  pthread_mutex_unlock(&timer_alarm_mutex);
 
1945
 
 
1946
  return(0);
 
1947
}
 
1948
 
 
1949
pthread_handler_t run_task(void *p)
 
1950
{
 
1951
  uint64_t counter= 0, queries;
 
1952
  uint64_t detach_counter;
 
1953
  unsigned int commit_counter;
 
1954
  drizzle_con_st con;
 
1955
  drizzle_result_st result;
 
1956
  drizzle_row_t row;
 
1957
  Statement *ptr;
 
1958
  ThreadContext *ctx= (ThreadContext *)p;
 
1959
 
 
1960
  pthread_mutex_lock(&sleeper_mutex);
 
1961
  while (master_wakeup)
 
1962
  {
 
1963
    pthread_cond_wait(&sleep_threshhold, &sleeper_mutex);
 
1964
  }
 
1965
  pthread_mutex_unlock(&sleeper_mutex);
 
1966
 
 
1967
  slap_connect(&con, true);
 
1968
 
 
1969
  if (verbose >= 3)
 
1970
    printf("connected!\n");
 
1971
  queries= 0;
 
1972
 
 
1973
  commit_counter= 0;
 
1974
  if (commit_rate)
 
1975
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
1976
 
 
1977
limit_not_met:
 
1978
  for (ptr= ctx->getStmt(), detach_counter= 0;
 
1979
       ptr && ptr->getLength();
 
1980
       ptr= ptr->getNext(), detach_counter++)
 
1981
  {
 
1982
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
1983
    {
 
1984
      slap_close(&con);
 
1985
      slap_connect(&con, true);
 
1986
    }
 
1987
 
 
1988
    /*
 
1989
      We have to execute differently based on query type. This should become a function.
 
1990
    */
 
1991
    if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
1992
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
 
1993
    {
 
1994
      int length;
 
1995
      unsigned int key_val;
 
1996
      char buffer[HUGE_STRING_LENGTH];
 
1997
 
 
1998
      /*
 
1999
        This should only happen if some sort of new engine was
 
2000
        implemented that didn't properly handle UPDATEs.
 
2001
 
 
2002
        Just in case someone runs this under an experimental engine we don't
 
2003
        want a crash so the if() is placed here.
 
2004
      */
 
2005
      assert(primary_keys.size());
 
2006
      if (primary_keys.size())
 
2007
      {
 
2008
        key_val= (unsigned int)(random() % primary_keys.size());
 
2009
        const char *key;
 
2010
        key= primary_keys[key_val].c_str();
 
2011
 
 
2012
        assert(key);
 
2013
 
 
2014
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
 
2015
                         (int)ptr->getLength(), ptr->getString(), key);
 
2016
 
 
2017
        if (run_query(&con, &result, buffer, length))
 
2018
        {
 
2019
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2020
                  internal::my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
 
2021
          exit(1);
 
2022
        }
 
2023
      }
 
2024
    }
 
2025
    else
 
2026
    {
 
2027
      if (run_query(&con, &result, ptr->getString(), ptr->getLength()))
 
2028
      {
 
2029
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2030
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
 
2031
        exit(1);
 
2032
      }
 
2033
    }
 
2034
 
 
2035
    if (!opt_only_print)
 
2036
    {
 
2037
      while ((row = drizzle_row_next(&result)))
 
2038
        counter++;
 
2039
      drizzle_result_free(&result);
 
2040
    }
 
2041
    queries++;
 
2042
 
 
2043
    if (commit_rate && (++commit_counter == commit_rate))
 
2044
    {
 
2045
      commit_counter= 0;
 
2046
      run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
2047
    }
 
2048
 
 
2049
    /* If the timer is set, and the alarm is not active then end */
 
2050
    if (opt_timer_length && timer_alarm == false)
 
2051
      goto end;
 
2052
 
 
2053
    /* If limit has been reached, and we are not in a timer_alarm just end */
 
2054
    if (ctx->getLimit() && queries == ctx->getLimit() && timer_alarm == false)
 
2055
      goto end;
 
2056
  }
 
2057
 
 
2058
  if (opt_timer_length && timer_alarm == true)
 
2059
    goto limit_not_met;
 
2060
 
 
2061
  if (ctx->getLimit() && queries < ctx->getLimit())
 
2062
    goto limit_not_met;
 
2063
 
 
2064
 
 
2065
end:
 
2066
  if (commit_rate)
 
2067
    run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
2068
 
 
2069
  slap_close(&con);
 
2070
 
 
2071
  pthread_mutex_lock(&counter_mutex);
 
2072
  thread_counter--;
 
2073
  pthread_cond_signal(&count_threshhold);
 
2074
  pthread_mutex_unlock(&counter_mutex);
 
2075
 
 
2076
  delete ctx;
 
2077
 
 
2078
  return(0);
2039
2079
}
2040
2080
 
2041
2081
/*
2042
2082
  Parse records from comma seperated string. : is a reserved character and is used for options
2043
2083
  on variables.
2044
2084
*/
2045
 
uint32_t parse_option(const char *origin, OptionString **stmt, char delm)
 
2085
uint
 
2086
parse_option(const char *origin, OptionString **stmt, char delm)
2046
2087
{
2047
2088
  char *string;
2048
2089
  char *begin_ptr;
2092
2133
    if (tmp->getString() == NULL)
2093
2134
    {
2094
2135
      fprintf(stderr,"Error allocating memory while parsing options\n");
2095
 
      abort();
 
2136
      exit(1);
2096
2137
    }
2097
2138
 
2098
2139
    if (isspace(*begin_ptr))
2115
2156
  Raw parsing interface. If you want the slap specific parser look at
2116
2157
  parse_option.
2117
2158
*/
2118
 
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm)
 
2159
uint
 
2160
parse_delimiter(const char *script, Statement **stmt, char delm)
2119
2161
{
2120
2162
  char *retstr;
2121
2163
  char *ptr= (char *)script;
2132
2174
    if (tmp == NULL)
2133
2175
    {
2134
2176
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2135
 
      abort();
 
2177
      exit(1);
2136
2178
    }
2137
2179
 
2138
2180
    count++;
2141
2183
    if (tmp->getString() == NULL)
2142
2184
    {
2143
2185
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2144
 
      abort();
 
2186
      exit(1);
2145
2187
    }
2146
2188
 
2147
2189
    memcpy(tmp->getString(), ptr, tmp->getLength());
2156
2198
    if (tmp->getString() == NULL)
2157
2199
    {
2158
2200
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2159
 
      abort();
 
2201
      exit(1);
2160
2202
    }
2161
2203
    memcpy(tmp->getString(), ptr, tmp->getLength());
2162
2204
    count++;
2171
2213
  number ranges from a comma seperated string.
2172
2214
  In restrospect, this is a lousy name from this function.
2173
2215
*/
2174
 
uint32_t parse_comma(const char *string, std::vector <uint32_t> &range)
 
2216
uint
 
2217
parse_comma(const char *string, std::vector <uint32_t> &range)
2175
2218
{
2176
 
  uint32_t count= 1; /* We know that there is always one */
 
2219
  unsigned int count= 1,x; /* We know that there is always one */
2177
2220
  char *retstr;
2178
2221
  char *ptr= (char *)string;
2179
 
  uint32_t *nptr;
 
2222
  unsigned int *nptr;
2180
2223
 
2181
2224
  for (;*ptr; ptr++)
2182
2225
    if (*ptr == ',') count++;
2186
2229
  nptr= &range[0];
2187
2230
 
2188
2231
  ptr= (char *)string;
2189
 
  uint32_t x= 0;
 
2232
  x= 0;
2190
2233
  while ((retstr= strchr(ptr,',')))
2191
2234
  {
2192
2235
    nptr[x++]= atoi(ptr);
2197
2240
  return count;
2198
2241
}
2199
2242
 
2200
 
void print_conclusions(Conclusions &con)
 
2243
void
 
2244
print_conclusions(Conclusions *con)
2201
2245
{
2202
2246
  printf("Benchmark\n");
2203
 
  if (con.getEngine())
2204
 
    printf("\tRunning for engine %s\n", con.getEngine());
2205
 
 
2206
 
  if (not opt_label.empty() || !opt_auto_generate_sql_type.empty())
 
2247
  if (con->getEngine())
 
2248
    printf("\tRunning for engine %s\n", con->getEngine());
 
2249
  if (!opt_label.empty() || !opt_auto_generate_sql_type.empty())
2207
2250
  {
2208
2251
    const char *ptr= opt_auto_generate_sql_type.c_str() ? opt_auto_generate_sql_type.c_str() : "query";
2209
2252
    printf("\tLoad: %s\n", !opt_label.empty() ? opt_label.c_str() : ptr);
2210
2253
  }
2211
2254
  printf("\tAverage Time took to generate schema and initial data: %ld.%03ld seconds\n",
2212
 
         con.getCreateAvgTiming() / 1000, con.getCreateAvgTiming() % 1000);
 
2255
         con->getCreateAvgTiming() / 1000, con->getCreateAvgTiming() % 1000);
2213
2256
  printf("\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
2214
 
         con.getAvgTiming() / 1000, con.getAvgTiming() % 1000);
 
2257
         con->getAvgTiming() / 1000, con->getAvgTiming() % 1000);
2215
2258
  printf("\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
2216
 
         con.getMinTiming() / 1000, con.getMinTiming() % 1000);
 
2259
         con->getMinTiming() / 1000, con->getMinTiming() % 1000);
2217
2260
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2218
 
         con.getMaxTiming() / 1000, con.getMaxTiming() % 1000);
 
2261
         con->getMaxTiming() / 1000, con->getMaxTiming() % 1000);
2219
2262
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2220
 
         con.getSumOfTime() / 1000, con.getSumOfTime() % 1000);
2221
 
  printf("\tStandard Deviation: %ld.%03ld\n", con.getStdDev() / 1000, con.getStdDev() % 1000);
2222
 
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con.getCreateCount());
 
2263
         con->getSumOfTime() / 1000, con->getSumOfTime() % 1000);
 
2264
  printf("\tStandard Deviation: %ld.%03ld\n", con->getStdDev() / 1000, con->getStdDev() % 1000);
 
2265
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->getCreateCount());
2223
2266
  printf("\tNumber of clients running queries: %u/%u\n",
2224
 
         con.getUsers(), con.getRealUsers());
 
2267
         con->getUsers(), con->getRealUsers());
2225
2268
  printf("\tNumber of times test was run: %u\n", iterations);
2226
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con.getAvgRows());
2227
 
 
2228
 
  uint64_t temp_val= failed_update_for_transaction; 
2229
 
  if (temp_val)
2230
 
    printf("\tFailed number of updates %"PRIu64"\n", temp_val);
2231
 
 
 
2269
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->getAvgRows());
2232
2270
  printf("\n");
2233
2271
}
2234
2272
 
2235
 
void print_conclusions_csv(Conclusions &con)
 
2273
void
 
2274
print_conclusions_csv(Conclusions *con)
2236
2275
{
 
2276
  unsigned int x;
2237
2277
  char buffer[HUGE_STRING_LENGTH];
2238
2278
  char label_buffer[HUGE_STRING_LENGTH];
2239
2279
  size_t string_len;
2241
2281
 
2242
2282
  memset(label_buffer, 0, sizeof(label_buffer));
2243
2283
 
2244
 
  if (not opt_label.empty())
 
2284
  if (!opt_label.empty())
2245
2285
  {
2246
2286
    string_len= opt_label.length();
2247
2287
 
2248
 
    for (uint32_t x= 0; x < string_len; x++)
 
2288
    for (x= 0; x < string_len; x++)
2249
2289
    {
2250
2290
      if (temp_label[x] == ',')
2251
2291
        label_buffer[x]= '-';
2253
2293
        label_buffer[x]= temp_label[x] ;
2254
2294
    }
2255
2295
  }
2256
 
  else if (not opt_auto_generate_sql_type.empty())
 
2296
  else if (!opt_auto_generate_sql_type.empty())
2257
2297
  {
2258
2298
    string_len= opt_auto_generate_sql_type.length();
2259
2299
 
2260
 
    for (uint32_t x= 0; x < string_len; x++)
 
2300
    for (x= 0; x < string_len; x++)
2261
2301
    {
2262
2302
      if (opt_auto_generate_sql_type[x] == ',')
2263
2303
        label_buffer[x]= '-';
2273
2313
  snprintf(buffer, HUGE_STRING_LENGTH,
2274
2314
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2275
2315
           "%u,%u,%u,%"PRIu64"\n",
2276
 
           con.getEngine() ? con.getEngine() : "", /* Storage engine we ran against */
 
2316
           con->getEngine() ? con->getEngine() : "", /* Storage engine we ran against */
2277
2317
           label_buffer, /* Load type */
2278
 
           con.getAvgTiming() / 1000, con.getAvgTiming() % 1000, /* Time to load */
2279
 
           con.getMinTiming() / 1000, con.getMinTiming() % 1000, /* Min time */
2280
 
           con.getMaxTiming() / 1000, con.getMaxTiming() % 1000, /* Max time */
2281
 
           con.getSumOfTime() / 1000, con.getSumOfTime() % 1000, /* Total time */
2282
 
           con.getStdDev() / 1000, con.getStdDev() % 1000, /* Standard Deviation */
 
2318
           con->getAvgTiming() / 1000, con->getAvgTiming() % 1000, /* Time to load */
 
2319
           con->getMinTiming() / 1000, con->getMinTiming() % 1000, /* Min time */
 
2320
           con->getMaxTiming() / 1000, con->getMaxTiming() % 1000, /* Max time */
 
2321
           con->getSumOfTime() / 1000, con->getSumOfTime() % 1000, /* Total time */
 
2322
           con->getStdDev() / 1000, con->getStdDev() % 1000, /* Standard Deviation */
2283
2323
           iterations, /* Iterations */
2284
 
           con.getUsers(), /* Children used max_timing */
2285
 
           con.getRealUsers(), /* Children used max_timing */
2286
 
           con.getAvgRows()  /* Queries run */
 
2324
           con->getUsers(), /* Children used max_timing */
 
2325
           con->getRealUsers(), /* Children used max_timing */
 
2326
           con->getAvgRows()  /* Queries run */
2287
2327
           );
2288
2328
  size_t buff_len= strlen(buffer);
2289
2329
  ssize_t write_ret= write(csv_file, (unsigned char*) buffer, buff_len);
2296
2336
  }
2297
2337
}
2298
2338
 
2299
 
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
 
2339
void
 
2340
generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
2300
2341
{
2301
2342
  Stats *ptr;
2302
 
  uint32_t x;
 
2343
  unsigned int x;
2303
2344
 
2304
2345
  con->setMinTiming(sptr->getTiming());
2305
2346
  con->setMaxTiming(sptr->getTiming());
2329
2370
  else
2330
2371
    con->setEngine(NULL);
2331
2372
 
2332
 
  standard_deviation(*con, sptr);
 
2373
  standard_deviation(con, sptr);
2333
2374
 
2334
2375
  /* Now we do the create time operations */
2335
2376
  con->setCreateMinTiming(sptr->getCreateTiming());
2365
2406
  }
2366
2407
}
2367
2408
 
2368
 
void statement_cleanup(Statement *stmt)
 
2409
void
 
2410
statement_cleanup(Statement *stmt)
2369
2411
{
2370
2412
  Statement *ptr, *nptr;
2371
 
  if (not stmt)
 
2413
  if (!stmt)
2372
2414
    return;
2373
2415
 
2374
2416
  for (ptr= stmt; ptr; ptr= nptr)
2378
2420
  }
2379
2421
}
2380
2422
 
2381
 
void slap_close(drizzle_con_st &con)
 
2423
void
 
2424
slap_close(drizzle_con_st *con)
2382
2425
{
2383
 
  drizzle_free(drizzle_con_drizzle(&con));
 
2426
  if (opt_only_print)
 
2427
    return;
 
2428
 
 
2429
  drizzle_free(drizzle_con_drizzle(con));
2384
2430
}
2385
2431
 
2386
 
void slap_connect(drizzle_con_st &con, bool connect_to_schema)
 
2432
void
 
2433
slap_connect(drizzle_con_st *con, bool connect_to_schema)
2387
2434
{
2388
2435
  /* Connect to server */
2389
2436
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2391
2438
  drizzle_return_t ret;
2392
2439
  drizzle_st *drizzle;
2393
2440
 
 
2441
  if (opt_only_print)
 
2442
    return;
 
2443
 
2394
2444
  if (opt_delayed_start)
2395
2445
    usleep(random()%opt_delayed_start);
2396
2446
 
2397
2447
  if ((drizzle= drizzle_create(NULL)) == NULL ||
2398
 
      drizzle_con_add_tcp(drizzle, &con, host.c_str(), opt_drizzle_port,
 
2448
      drizzle_con_add_tcp(drizzle, con, host.c_str(), opt_drizzle_port,
2399
2449
        user.c_str(),
2400
2450
        opt_password.c_str(),
2401
2451
        connect_to_schema ? create_schema_string.c_str() : NULL,
2402
2452
        use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL) == NULL)
2403
2453
  {
2404
 
    fprintf(stderr,"%s: Error creating drizzle object\n", SLAP_NAME);
2405
 
    abort();
 
2454
    fprintf(stderr,"%s: Error creating drizzle object\n", internal::my_progname);
 
2455
    exit(1);
2406
2456
  }
2407
2457
 
2408
 
  drizzle_set_context(drizzle, (void*)(connection_count.fetch_and_increment()));
2409
 
 
2410
 
  if (opt_only_print)
2411
 
    return;
2412
 
 
2413
2458
  for (uint32_t x= 0; x < 10; x++)
2414
2459
  {
2415
 
    if ((ret= drizzle_con_connect(&con)) == DRIZZLE_RETURN_OK)
 
2460
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2416
2461
    {
2417
2462
      /* Connect suceeded */
2418
2463
      connect_error= 0;
2422
2467
  }
2423
2468
  if (connect_error)
2424
2469
  {
2425
 
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", SLAP_NAME,
2426
 
            ret, drizzle_con_error(&con));
2427
 
    abort();
 
2470
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", internal::my_progname,
 
2471
            ret, drizzle_con_error(con));
 
2472
    exit(1);
2428
2473
  }
 
2474
 
 
2475
  return;
2429
2476
}
2430
2477
 
2431
 
void standard_deviation(Conclusions &con, Stats *sptr)
 
2478
void
 
2479
standard_deviation (Conclusions *con, Stats *sptr)
2432
2480
{
 
2481
  unsigned int x;
2433
2482
  long int sum_of_squares;
2434
2483
  double the_catch;
2435
2484
  Stats *ptr;
2436
2485
 
2437
2486
  if (iterations == 1 || iterations == 0)
2438
2487
  {
2439
 
    con.setStdDev(0);
 
2488
    con->setStdDev(0);
2440
2489
    return;
2441
2490
  }
2442
2491
 
2443
 
  uint32_t x;
2444
2492
  for (ptr= sptr, x= 0, sum_of_squares= 0; x < iterations; ptr++, x++)
2445
2493
  {
2446
2494
    long int deviation;
2447
2495
 
2448
 
    deviation= ptr->getTiming() - con.getAvgTiming();
 
2496
    deviation= ptr->getTiming() - con->getAvgTiming();
2449
2497
    sum_of_squares+= deviation*deviation;
2450
2498
  }
2451
2499
 
2452
2500
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2453
 
  con.setStdDev((long int)the_catch);
 
2501
  con->setStdDev((long int)the_catch);
2454
2502
}