~stewart/drizzle/embedded-innodb-autoincrement

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Stewart Smith
  • Date: 2010-05-12 12:04:58 UTC
  • mfrom: (1283.120.50 staging)
  • mto: This revision was merged to the branch mainline in revision 1430.
  • Revision ID: stewart@flamingspork.com-20100512120458-grl8fnvsw00z2l1o
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
199
199
  DELETE_TYPE_REQUIRES_PREFIX= 6
200
200
} slap_query_type;
201
201
 
202
 
typedef struct statement statement;
203
 
 
204
 
struct statement {
 
202
class Statement;
 
203
 
 
204
class Statement 
 
205
{
 
206
public:
 
207
  Statement(char *in_string,
 
208
            size_t in_length,
 
209
            slap_query_type in_type,
 
210
            char *in_option,
 
211
            size_t in_option_length,
 
212
            Statement *in_next)
 
213
    :
 
214
    string(in_string),
 
215
    length(in_length),
 
216
    type(in_type),
 
217
    option(in_option),
 
218
    option_length(in_option_length),
 
219
    next(in_next)
 
220
    {}
 
221
 
 
222
  Statement()
 
223
    :
 
224
    string(NULL),
 
225
    length(0),
 
226
    type(),
 
227
    option(NULL),
 
228
    option_length(0),
 
229
    next(NULL)
 
230
    {}
 
231
   
 
232
  char *getString() const
 
233
  {
 
234
    return string;
 
235
  }
 
236
 
 
237
  size_t getLength() const
 
238
  {
 
239
    return length;
 
240
  }
 
241
 
 
242
  slap_query_type getType() const
 
243
  {
 
244
    return type;
 
245
  }
 
246
 
 
247
  char *getOption() const
 
248
  {
 
249
    return option;
 
250
  }
 
251
 
 
252
  size_t getOptionLength() const
 
253
  {
 
254
    return option_length;
 
255
  }
 
256
 
 
257
  Statement *getNext() const
 
258
  {
 
259
    return next;
 
260
  }
 
261
 
 
262
  void setString(char *in_string)
 
263
  {
 
264
    string= in_string;
 
265
  }
 
266
 
 
267
  void setString(size_t in_length, char in_char)
 
268
  {
 
269
    string[in_length]= in_char;
 
270
  }
 
271
 
 
272
  void setLength(size_t in_length)
 
273
  {
 
274
    length= in_length;
 
275
  }
 
276
 
 
277
  void setType(slap_query_type in_type)
 
278
  {
 
279
    type= in_type;
 
280
  }
 
281
 
 
282
  void setOption(char *in_option)
 
283
  {
 
284
    option= in_option;
 
285
  }
 
286
 
 
287
   void setOptionLength(size_t in_option_length)
 
288
  {
 
289
    option_length= in_option_length;
 
290
  }
 
291
 
 
292
  void setNext(Statement *in_next)
 
293
  {
 
294
    next= in_next;
 
295
  }
 
296
 
 
297
private:
205
298
  char *string;
206
299
  size_t length;
207
300
  slap_query_type type;
208
301
  char *option;
209
302
  size_t option_length;
210
 
  statement *next;
 
303
  Statement *next;
211
304
};
212
305
 
213
 
typedef struct option_string option_string;
214
 
 
215
 
struct option_string {
 
306
class OptionString;
 
307
 
 
308
class OptionString 
 
309
{
 
310
public:
 
311
  OptionString(char *in_string,
 
312
               size_t in_length,
 
313
               char *in_option,
 
314
               size_t in_option_length,
 
315
               OptionString *in_next)
 
316
    :
 
317
    string(in_string),
 
318
    length(in_length),
 
319
    option(in_option),
 
320
    option_length(in_option_length),
 
321
    next(in_next)
 
322
    {}  
 
323
 
 
324
  OptionString()
 
325
    :
 
326
    string(NULL),
 
327
    length(0),
 
328
    option(NULL),
 
329
    option_length(0),
 
330
    next(NULL)
 
331
    {}
 
332
 
 
333
  char *getString() const
 
334
  {
 
335
    return string;
 
336
  }
 
337
 
 
338
  size_t getLength() const
 
339
  {
 
340
    return length;
 
341
  }
 
342
 
 
343
  char *getOption() const
 
344
  {
 
345
  return option;
 
346
  }
 
347
 
 
348
  size_t getOptionLength() const
 
349
  {
 
350
    return option_length;
 
351
  }
 
352
 
 
353
  OptionString *getNext() const
 
354
  {
 
355
    return next;
 
356
  }
 
357
 
 
358
  void setString(char *in_string)
 
359
  {
 
360
    string= in_string;
 
361
  }
 
362
 
 
363
  void setOptionLength(size_t in_option_length)
 
364
  {
 
365
    option_length= in_option_length;
 
366
  }
 
367
 
 
368
  void setLength(size_t in_length)
 
369
  {
 
370
    length= in_length;
 
371
  }
 
372
 
 
373
  void setOption(char *in_option)
 
374
  {
 
375
    option= in_option;
 
376
  }
 
377
 
 
378
  void setOption(size_t in_option_length, char in_char)
 
379
  {
 
380
    option[in_option_length]= in_char;
 
381
  }
 
382
 
 
383
  void setNext(OptionString *in_next)
 
384
  {
 
385
    next= in_next;
 
386
  }
 
387
  
 
388
private:
216
389
  char *string;
217
390
  size_t length;
218
391
  char *option;
219
392
  size_t option_length;
220
 
  option_string *next;
 
393
  OptionString *next;
221
394
};
222
395
 
223
 
typedef struct stats stats;
224
 
 
225
 
struct stats {
 
396
class Stats;
 
397
 
 
398
class Stats 
 
399
{
 
400
public:
 
401
  Stats(long int in_timing,
 
402
        uint32_t in_users,
 
403
        uint32_t in_real_users,
 
404
        uint32_t in_rows,
 
405
        long int in_create_timing,
 
406
        uint64_t in_create_count)
 
407
    :
 
408
    timing(in_timing),
 
409
    users(in_users),
 
410
    real_users(in_real_users),
 
411
    rows(in_rows),
 
412
    create_timing(in_create_timing),
 
413
    create_count(in_create_count)
 
414
    {}
 
415
 
 
416
  Stats()
 
417
    :
 
418
    timing(0),
 
419
    users(0),
 
420
    real_users(0),
 
421
    rows(0),
 
422
    create_timing(0),
 
423
    create_count(0)
 
424
    {}
 
425
 
 
426
  long int getTiming() const
 
427
  {
 
428
    return timing;
 
429
  }
 
430
 
 
431
  uint32_t getUsers() const
 
432
  {
 
433
    return users;
 
434
  }   
 
435
 
 
436
  uint32_t getRealUsers() const
 
437
  {
 
438
    return real_users;
 
439
  }
 
440
 
 
441
  uint64_t getRows() const
 
442
  {
 
443
    return rows;
 
444
  }
 
445
 
 
446
  long int getCreateTiming() const
 
447
  {
 
448
    return create_timing;
 
449
  }
 
450
 
 
451
  uint64_t getCreateCount() const
 
452
  {
 
453
    return create_count;
 
454
  }
 
455
 
 
456
  void setTiming(long int in_timing)
 
457
  {
 
458
  timing= in_timing;
 
459
  }
 
460
 
 
461
  void setUsers(uint32_t in_users)
 
462
  {
 
463
    users= in_users;
 
464
  }
 
465
 
 
466
  void setRealUsers(uint32_t in_real_users)
 
467
  {
 
468
    real_users= in_real_users;
 
469
  }
 
470
 
 
471
  void setRows(uint64_t in_rows)
 
472
  {
 
473
    rows= in_rows;
 
474
  }
 
475
   
 
476
  void setCreateTiming(long int in_create_timing)
 
477
  {
 
478
    create_timing= in_create_timing;
 
479
  }
 
480
 
 
481
  void setCreateCount(uint64_t in_create_count)
 
482
  {
 
483
  create_count= in_create_count;
 
484
  }
 
485
  
 
486
private:
226
487
  long int timing;
227
488
  uint32_t users;
228
489
  uint32_t real_users;
231
492
  uint64_t create_count;
232
493
};
233
494
 
234
 
typedef struct thread_context thread_context;
235
 
 
236
 
struct thread_context {
237
 
  statement *stmt;
 
495
class ThreadContext;
 
496
 
 
497
class ThreadContext 
 
498
{
 
499
public:
 
500
  ThreadContext(Statement *in_stmt,
 
501
                uint64_t in_limit)
 
502
    :
 
503
    stmt(in_stmt),
 
504
    limit(in_limit)
 
505
    {}
 
506
 
 
507
  ThreadContext()
 
508
    :
 
509
    stmt(),
 
510
    limit(0)
 
511
    {}
 
512
 
 
513
  Statement *getStmt() const
 
514
  {
 
515
    return stmt;
 
516
  }
 
517
 
 
518
  uint64_t getLimit() const
 
519
  {
 
520
    return limit;
 
521
  }
 
522
 
 
523
  void setStmt(Statement *in_stmt)
 
524
  {
 
525
    stmt= in_stmt;
 
526
  }
 
527
 
 
528
  void setLimit(uint64_t in_limit)
 
529
  {
 
530
    limit= in_limit;
 
531
  }  
 
532
 
 
533
private:
 
534
  Statement *stmt;
238
535
  uint64_t limit;
239
536
};
240
537
 
241
 
typedef struct conclusions conclusions;
242
 
 
243
 
struct conclusions {
 
538
class Conclusions;
 
539
 
 
540
class Conclusions 
 
541
{
 
542
 
 
543
public:
 
544
  Conclusions(char *in_engine,
 
545
              long int in_avg_timing,
 
546
              long int in_max_timing,
 
547
              long int in_min_timing,
 
548
              uint32_t in_users,
 
549
              uint32_t in_real_users,
 
550
              uint64_t in_avg_rows,
 
551
              long int in_sum_of_time,
 
552
              long int in_std_dev,
 
553
              long int in_create_avg_timing,
 
554
              long int in_create_max_timing,
 
555
              long int in_create_min_timing,
 
556
              uint64_t in_create_count,
 
557
              uint64_t in_max_rows,
 
558
              uint64_t in_min_rows)
 
559
    :
 
560
    engine(in_engine),
 
561
    avg_timing(in_avg_timing),
 
562
    max_timing(in_max_timing),
 
563
    min_timing(in_min_timing),
 
564
    users(in_users),
 
565
    real_users(in_real_users),
 
566
    avg_rows(in_avg_rows),
 
567
    sum_of_time(in_sum_of_time),
 
568
    std_dev(in_std_dev),
 
569
    create_avg_timing(in_create_avg_timing),
 
570
    create_max_timing(in_create_max_timing),
 
571
    create_min_timing(in_create_min_timing),
 
572
    create_count(in_create_count),
 
573
    max_rows(in_max_rows),
 
574
    min_rows(in_min_rows)
 
575
    {}
 
576
 
 
577
  Conclusions()
 
578
    :
 
579
    engine(NULL),
 
580
    avg_timing(0),
 
581
    max_timing(0),
 
582
    min_timing(0),
 
583
    users(0),
 
584
    real_users(0),
 
585
    avg_rows(0),
 
586
    sum_of_time(0),
 
587
    std_dev(0),
 
588
    create_avg_timing(0),
 
589
    create_max_timing(0),
 
590
    create_min_timing(0),
 
591
    create_count(0),
 
592
    max_rows(0),
 
593
    min_rows(0)
 
594
    {}
 
595
 
 
596
  char *getEngine() const
 
597
  {
 
598
    return engine;
 
599
  }
 
600
  
 
601
  long int getAvgTiming() const
 
602
  {
 
603
    return avg_timing;
 
604
  }
 
605
 
 
606
  long int getMaxTiming() const
 
607
  {
 
608
    return max_timing;
 
609
  }
 
610
 
 
611
  long int getMinTiming() const
 
612
  {
 
613
    return min_timing;
 
614
  }
 
615
 
 
616
  uint32_t getUsers() const
 
617
  {
 
618
    return users;
 
619
  }
 
620
 
 
621
  uint32_t getRealUsers() const
 
622
  {
 
623
    return real_users;
 
624
  }
 
625
 
 
626
  uint64_t getAvgRows() const
 
627
  {
 
628
    return avg_rows;
 
629
  }   
 
630
 
 
631
  long int getSumOfTime() const
 
632
  {
 
633
    return sum_of_time;
 
634
  }
 
635
 
 
636
  long int getStdDev() const
 
637
  {
 
638
    return std_dev;
 
639
  }
 
640
 
 
641
  long int getCreateAvgTiming() const
 
642
  {
 
643
    return create_avg_timing;
 
644
  }
 
645
 
 
646
  long int getCreateMaxTiming() const
 
647
  {
 
648
    return create_max_timing;
 
649
  }
 
650
 
 
651
  long int getCreateMinTiming() const
 
652
  {
 
653
    return create_min_timing;
 
654
  }
 
655
   
 
656
  uint64_t getCreateCount() const
 
657
  {
 
658
    return create_count;
 
659
  }
 
660
 
 
661
  uint64_t getMinRows() const
 
662
  {
 
663
    return min_rows;
 
664
  }
 
665
 
 
666
  uint64_t getMaxRows() const
 
667
  {
 
668
    return max_rows;
 
669
  }
 
670
 
 
671
  void setEngine(char *in_engine) 
 
672
  {
 
673
    engine= in_engine;
 
674
  }
 
675
  
 
676
  void setAvgTiming(long int in_avg_timing) 
 
677
  {
 
678
    avg_timing= in_avg_timing;
 
679
  }
 
680
 
 
681
  void setMaxTiming(long int in_max_timing) 
 
682
  {
 
683
    max_timing= in_max_timing;
 
684
  }
 
685
 
 
686
  void setMinTiming(long int in_min_timing) 
 
687
  {
 
688
    min_timing= in_min_timing;
 
689
  }
 
690
 
 
691
  void setUsers(uint32_t in_users) 
 
692
  {
 
693
    users= in_users;
 
694
  }
 
695
 
 
696
  void setRealUsers(uint32_t in_real_users) 
 
697
  {
 
698
    real_users= in_real_users;
 
699
  }
 
700
 
 
701
  void setAvgRows(uint64_t in_avg_rows) 
 
702
  {
 
703
    avg_rows= in_avg_rows;
 
704
  }   
 
705
 
 
706
  void setSumOfTime(long int in_sum_of_time) 
 
707
  {
 
708
    sum_of_time= in_sum_of_time;
 
709
  }
 
710
 
 
711
  void setStdDev(long int in_std_dev) 
 
712
  {
 
713
    std_dev= in_std_dev;
 
714
  }
 
715
 
 
716
  void setCreateAvgTiming(long int in_create_avg_timing) 
 
717
  {
 
718
    create_avg_timing= in_create_avg_timing;
 
719
  }
 
720
 
 
721
  void setCreateMaxTiming(long int in_create_max_timing) 
 
722
  {
 
723
    create_max_timing= in_create_max_timing;
 
724
  }
 
725
 
 
726
  void setCreateMinTiming(long int in_create_min_timing) 
 
727
  {
 
728
    create_min_timing= in_create_min_timing;
 
729
  }
 
730
   
 
731
  void setCreateCount(uint64_t in_create_count) 
 
732
  {
 
733
    create_count= in_create_count;
 
734
  }
 
735
 
 
736
  void setMinRows(uint64_t in_min_rows) 
 
737
  {
 
738
    min_rows= in_min_rows;
 
739
  }
 
740
 
 
741
  void setMaxRows(uint64_t in_max_rows) 
 
742
  {
 
743
    max_rows= in_max_rows;
 
744
  }
 
745
 
 
746
private:
244
747
  char *engine;
245
748
  long int avg_timing;
246
749
  long int max_timing;
260
763
  uint64_t min_rows;
261
764
};
262
765
 
263
 
static option_string *engine_options= NULL;
264
 
static option_string *query_options= NULL;
265
 
static statement *pre_statements= NULL;
266
 
static statement *post_statements= NULL;
267
 
static statement *create_statements= NULL;
268
 
 
269
 
static statement **query_statements= NULL;
 
766
 
 
767
static OptionString *engine_options= NULL;
 
768
static OptionString *query_options= NULL;
 
769
static Statement *pre_statements= NULL;
 
770
static Statement *post_statements= NULL;
 
771
static Statement *create_statements= NULL;
 
772
 
 
773
static Statement **query_statements= NULL;
270
774
static unsigned int query_statements_count;
271
775
 
272
776
 
273
777
/* Prototypes */
274
 
void print_conclusions(conclusions *con);
275
 
void print_conclusions_csv(conclusions *con);
276
 
void generate_stats(conclusions *con, option_string *eng, stats *sptr);
 
778
void print_conclusions(Conclusions *con);
 
779
void print_conclusions_csv(Conclusions *con);
 
780
void generate_stats(Conclusions *con, OptionString *eng, Stats *sptr);
277
781
uint32_t parse_comma(const char *string, uint32_t **range);
278
 
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
279
 
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
 
782
uint32_t parse_delimiter(const char *script, Statement **stmt, char delm);
 
783
uint32_t parse_option(const char *origin, OptionString **stmt, char delm);
280
784
static int drop_schema(drizzle_con_st *con, const char *db);
281
785
uint32_t get_random_string(char *buf, size_t size);
282
 
static statement *build_table_string(void);
283
 
static statement *build_insert_string(void);
284
 
static statement *build_update_string(void);
285
 
static statement * build_select_string(bool key);
286
 
static int generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt);
 
786
static Statement *build_table_string(void);
 
787
static Statement *build_insert_string(void);
 
788
static Statement *build_update_string(void);
 
789
static Statement * build_select_string(bool key);
 
790
static int generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt);
287
791
static int drop_primary_key_list(void);
288
 
static int create_schema(drizzle_con_st *con, const char *db, statement *stmt,
289
 
                         option_string *engine_stmt, stats *sptr);
290
 
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
 
792
static int create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
 
793
                         OptionString *engine_stmt, Stats *sptr);
 
794
static int run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur,
291
795
                         uint64_t limit);
292
796
extern "C" pthread_handler_t run_task(void *p);
293
797
extern "C" pthread_handler_t timer_thread(void *p);
294
 
void statement_cleanup(statement *stmt);
295
 
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);
 
798
void statement_cleanup(Statement *stmt);
 
799
void option_cleanup(OptionString *stmt);
 
800
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr);
 
801
static int run_statements(drizzle_con_st *con, Statement *stmt);
298
802
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
299
803
void slap_close(drizzle_con_st *con);
300
804
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
301
 
void standard_deviation (conclusions *con, stats *sptr);
 
805
void standard_deviation (Conclusions *con, Stats *sptr);
302
806
 
303
807
static const char ALPHANUMERICS[]=
304
808
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
320
824
int main(int argc, char **argv)
321
825
{
322
826
  drizzle_con_st con;
323
 
  option_string *eptr;
 
827
  OptionString *eptr;
324
828
  unsigned int x;
325
829
 
326
830
  internal::my_init();
393
897
    if (!opt_preserve)
394
898
      drop_schema(&con, create_schema_string);
395
899
 
396
 
  } while (eptr ? (eptr= eptr->next) : 0);
 
900
  } while (eptr ? (eptr= eptr->getNext()) : 0);
397
901
 
398
902
  if (opt_burnin)
399
903
    goto burnin;
432
936
  return 0;
433
937
}
434
938
 
435
 
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr)
 
939
void concurrency_loop(drizzle_con_st *con, uint32_t current, OptionString *eptr)
436
940
{
437
941
  unsigned int x;
438
 
  stats *head_sptr;
439
 
  stats *sptr;
440
 
  conclusions conclusion;
 
942
  Stats *head_sptr;
 
943
  Stats *sptr;
 
944
  Conclusions conclusion;
441
945
  uint64_t client_limit;
442
946
 
443
 
  head_sptr= (stats *)malloc(sizeof(stats) * iterations);
 
947
  head_sptr= (Stats *)malloc(sizeof(Stats) * iterations);
444
948
  if (head_sptr == NULL)
445
949
  {
446
950
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
447
951
    exit(1);
448
952
  }
449
 
  memset(head_sptr, 0, sizeof(stats) * iterations);
 
953
  memset(head_sptr, 0, sizeof(Stats) * iterations);
450
954
 
451
 
  memset(&conclusion, 0, sizeof(conclusions));
 
955
  memset(&conclusion, 0, sizeof(Conclusions));
452
956
 
453
957
  if (auto_actual_queries)
454
958
    client_limit= auto_actual_queries;
742
1246
    if (strlen(endchar) != 0)
743
1247
    {
744
1248
      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;
 
1249
      exit(1);
746
1250
    }
747
1251
    /* If the port number is > 65535 it is not a valid port
748
1252
       This also helps with potential data loss casting unsigned long to a
750
1254
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
751
1255
    {
752
1256
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
753
 
      return EXIT_ARGUMENT_INVALID;
 
1257
      exit(1);
754
1258
    }
755
1259
    else
756
1260
    {
768
1272
      {
769
1273
        fprintf(stderr, "Memory allocation error while copying password. "
770
1274
                        "Aborting.\n");
771
 
        return EXIT_OUT_OF_MEMORY;
 
1275
        exit(ENOMEM);
772
1276
      }
773
1277
      while (*argument)
774
1278
      {
815
1319
  This function builds a create table query if the user opts to not supply
816
1320
  a file or string containing a create table statement
817
1321
*/
818
 
static statement *
 
1322
static Statement *
819
1323
build_table_string(void)
820
1324
{
821
1325
  char       buf[HUGE_STRING_LENGTH];
822
1326
  unsigned int        col_count;
823
 
  statement *ptr;
 
1327
  Statement *ptr;
824
1328
  string table_string;
825
1329
 
826
1330
  table_string.reserve(HUGE_STRING_LENGTH);
936
1440
    }
937
1441
 
938
1442
  table_string.append(")");
939
 
  ptr= (statement *)malloc(sizeof(statement));
 
1443
  ptr= (Statement *)malloc(sizeof(Statement));
940
1444
  if (ptr == NULL)
941
1445
  {
942
1446
    fprintf(stderr, "Memory Allocation error in creating table\n");
943
1447
    exit(1);
944
1448
  }
945
 
  memset(ptr, 0, sizeof(statement));
946
 
  ptr->string = (char *)malloc(table_string.length()+1);
947
 
  if (ptr->string == NULL)
 
1449
  memset(ptr, 0, sizeof(Statement));
 
1450
  ptr->setString((char *)malloc(table_string.length()+1));
 
1451
  if (ptr->getString()==NULL)
948
1452
  {
949
1453
    fprintf(stderr, "Memory Allocation error in creating table\n");
950
1454
    exit(1);
951
1455
  }
952
 
  memset(ptr->string, 0, table_string.length()+1);
953
 
  ptr->length= table_string.length()+1;
954
 
  ptr->type= CREATE_TABLE_TYPE;
955
 
  strcpy(ptr->string, table_string.c_str());
 
1456
  memset(ptr->getString(), 0, table_string.length()+1);
 
1457
  ptr->setLength(table_string.length()+1);
 
1458
  ptr->setType(CREATE_TABLE_TYPE);
 
1459
  strcpy(ptr->getString(), table_string.c_str());
956
1460
  return(ptr);
957
1461
}
958
1462
 
962
1466
  This function builds insert statements when the user opts to not supply
963
1467
  an insert file or string containing insert data
964
1468
*/
965
 
static statement *
 
1469
static Statement *
966
1470
build_update_string(void)
967
1471
{
968
1472
  char       buf[HUGE_STRING_LENGTH];
969
1473
  unsigned int        col_count;
970
 
  statement *ptr;
 
1474
  Statement *ptr;
971
1475
  string update_string;
972
1476
 
973
1477
  update_string.reserve(HUGE_STRING_LENGTH);
1012
1516
    update_string.append(" WHERE id = ");
1013
1517
 
1014
1518
 
1015
 
  ptr= (statement *)malloc(sizeof(statement));
 
1519
  ptr= (Statement *)malloc(sizeof(Statement));
1016
1520
  if (ptr == NULL)
1017
1521
  {
1018
1522
    fprintf(stderr, "Memory Allocation error in creating update\n");
1019
1523
    exit(1);
1020
1524
  }
1021
 
  memset(ptr, 0, sizeof(statement));
 
1525
  memset(ptr, 0, sizeof(Statement));
1022
1526
 
1023
 
  ptr->length= update_string.length()+1;
1024
 
  ptr->string= (char *)malloc(ptr->length);
1025
 
  if (ptr->string == NULL)
 
1527
  ptr->setLength(update_string.length()+1);
 
1528
  ptr->setString((char *)malloc(ptr->getLength()));
 
1529
  if (ptr->getString() == NULL)
1026
1530
  {
1027
1531
    fprintf(stderr, "Memory Allocation error in creating update\n");
1028
1532
    exit(1);
1029
1533
  }
1030
 
  memset(ptr->string, 0, ptr->length);
 
1534
  memset(ptr->getString(), 0, ptr->getLength());
1031
1535
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
1032
 
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
 
1536
    ptr->setType(UPDATE_TYPE_REQUIRES_PREFIX);
1033
1537
  else
1034
 
    ptr->type= UPDATE_TYPE;
1035
 
  strncpy(ptr->string, update_string.c_str(), ptr->length);
 
1538
    ptr->setType(UPDATE_TYPE);
 
1539
  strncpy(ptr->getString(), update_string.c_str(), ptr->getLength());
1036
1540
  return(ptr);
1037
1541
}
1038
1542
 
1043
1547
  This function builds insert statements when the user opts to not supply
1044
1548
  an insert file or string containing insert data
1045
1549
*/
1046
 
static statement *
 
1550
static Statement *
1047
1551
build_insert_string(void)
1048
1552
{
1049
1553
  char       buf[HUGE_STRING_LENGTH];
1050
1554
  unsigned int        col_count;
1051
 
  statement *ptr;
 
1555
  Statement *ptr;
1052
1556
  string insert_string;
1053
1557
 
1054
1558
  insert_string.reserve(HUGE_STRING_LENGTH);
1157
1661
 
1158
1662
  insert_string.append(")", 1);
1159
1663
 
1160
 
  if (!(ptr= (statement *)malloc(sizeof(statement))))
1161
 
  {
1162
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1163
 
    exit(1);
1164
 
  }
1165
 
  memset(ptr, 0, sizeof(statement));
1166
 
  ptr->length= insert_string.length()+1;
1167
 
  if (!(ptr->string= (char *)malloc(ptr->length)))
1168
 
  {
1169
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1170
 
    exit(1);
1171
 
  }
1172
 
  memset(ptr->string, 0, ptr->length);
1173
 
  ptr->type= INSERT_TYPE;
1174
 
  strcpy(ptr->string, insert_string.c_str());
 
1664
  if (!(ptr= (Statement *)malloc(sizeof(Statement))))
 
1665
  {
 
1666
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1667
    exit(1);
 
1668
  }
 
1669
  memset(ptr, 0, sizeof(Statement));
 
1670
  ptr->setLength(insert_string.length()+1);
 
1671
  ptr->setString((char *)malloc(ptr->getLength()));
 
1672
  if (ptr->getString()==NULL)
 
1673
  {
 
1674
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1675
    exit(1);
 
1676
  }
 
1677
  memset(ptr->getString(), 0, ptr->getLength());
 
1678
  ptr->setType(INSERT_TYPE);
 
1679
  strcpy(ptr->getString(), insert_string.c_str());
1175
1680
  return(ptr);
1176
1681
}
1177
1682
 
1182
1687
  This function builds a query if the user opts to not supply a query
1183
1688
  statement or file containing a query statement
1184
1689
*/
1185
 
static statement *
 
1690
static Statement *
1186
1691
build_select_string(bool key)
1187
1692
{
1188
1693
  char       buf[HUGE_STRING_LENGTH];
1189
1694
  unsigned int        col_count;
1190
 
  statement *ptr;
 
1695
  Statement *ptr;
1191
1696
  string query_string;
1192
1697
 
1193
1698
  query_string.reserve(HUGE_STRING_LENGTH);
1247
1752
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1248
1753
    query_string.append(" WHERE id = ");
1249
1754
 
1250
 
  ptr= (statement *)malloc(sizeof(statement));
 
1755
  ptr= (Statement *)malloc(sizeof(Statement));
1251
1756
  if (ptr == NULL)
1252
1757
  {
1253
1758
    fprintf(stderr, "Memory Allocation error in creating select\n");
1254
1759
    exit(1);
1255
1760
  }
1256
 
  memset(ptr, 0, sizeof(statement));
1257
 
  ptr->length= query_string.length()+1;
1258
 
  ptr->string= (char *)malloc(ptr->length);
1259
 
  if (ptr->string == NULL)
 
1761
  memset(ptr, 0, sizeof(Statement));
 
1762
  ptr->setLength(query_string.length()+1);
 
1763
  ptr->setString((char *)malloc(ptr->getLength()));
 
1764
  if (ptr->getString() == NULL)
1260
1765
  {
1261
1766
    fprintf(stderr, "Memory Allocation error in creating select\n");
1262
1767
    exit(1);
1263
1768
  }
1264
 
  memset(ptr->string, 0, ptr->length);
 
1769
  memset(ptr->getString(), 0, ptr->getLength());
1265
1770
  if ((key) &&
1266
1771
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1267
 
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
 
1772
    ptr->setType(SELECT_TYPE_REQUIRES_PREFIX);
1268
1773
  else
1269
 
    ptr->type= SELECT_TYPE;
1270
 
  strcpy(ptr->string, query_string.c_str());
 
1774
    ptr->setType(SELECT_TYPE);
 
1775
  strcpy(ptr->getString(), query_string.c_str());
1271
1776
  return(ptr);
1272
1777
}
1273
1778
 
1277
1782
  int ho_error;
1278
1783
  char *tmp_string;
1279
1784
  struct stat sbuf;
1280
 
  option_string *sql_type;
 
1785
  OptionString *sql_type;
1281
1786
  unsigned int sql_type_count= 0;
1282
1787
  ssize_t bytes_read= 0;
1283
1788
 
1344
1849
 
1345
1850
  if (num_int_cols_opt)
1346
1851
  {
1347
 
    option_string *str;
 
1852
    OptionString *str;
1348
1853
    parse_option(num_int_cols_opt, &str, ',');
1349
 
    num_int_cols= atoi(str->string);
1350
 
    if (str->option)
1351
 
      num_int_cols_index= atoi(str->option);
 
1854
    num_int_cols= atoi(str->getString());
 
1855
    if (str->getOption())
 
1856
      num_int_cols_index= atoi(str->getOption());
1352
1857
    option_cleanup(str);
1353
1858
  }
1354
1859
 
1355
1860
  if (num_char_cols_opt)
1356
1861
  {
1357
 
    option_string *str;
 
1862
    OptionString *str;
1358
1863
    parse_option(num_char_cols_opt, &str, ',');
1359
 
    num_char_cols= atoi(str->string);
1360
 
    if (str->option)
1361
 
      num_char_cols_index= atoi(str->option);
 
1864
    num_char_cols= atoi(str->getString());
 
1865
    if (str->getOption())
 
1866
      num_char_cols_index= atoi(str->getOption());
1362
1867
    else
1363
1868
      num_char_cols_index= 0;
1364
1869
    option_cleanup(str);
1366
1871
 
1367
1872
  if (num_blob_cols_opt)
1368
1873
  {
1369
 
    option_string *str;
 
1874
    OptionString *str;
1370
1875
    parse_option(num_blob_cols_opt, &str, ',');
1371
 
    num_blob_cols= atoi(str->string);
1372
 
    if (str->option)
 
1876
    num_blob_cols= atoi(str->getString());
 
1877
    if (str->getOption())
1373
1878
    {
1374
1879
      char *sep_ptr;
1375
1880
 
1376
 
      if ((sep_ptr= strchr(str->option, '/')))
 
1881
      if ((sep_ptr= strchr(str->getOption(), '/')))
1377
1882
      {
1378
 
        num_blob_cols_size_min= atoi(str->option);
 
1883
        num_blob_cols_size_min= atoi(str->getOption());
1379
1884
        num_blob_cols_size= atoi(sep_ptr+1);
1380
1885
      }
1381
1886
      else
1382
1887
      {
1383
 
        num_blob_cols_size_min= num_blob_cols_size= atoi(str->option);
 
1888
        num_blob_cols_size_min= num_blob_cols_size= atoi(str->getOption());
1384
1889
      }
1385
1890
    }
1386
1891
    else
1395
1900
  if (auto_generate_sql)
1396
1901
  {
1397
1902
    uint64_t x= 0;
1398
 
    statement *ptr_statement;
 
1903
    Statement *ptr_statement;
1399
1904
 
1400
1905
    if (verbose >= 2)
1401
1906
      printf("Building Create Statements for Auto\n");
1406
1911
    */
1407
1912
    for (ptr_statement= create_statements, x= 0;
1408
1913
         x < auto_generate_sql_unique_write_number;
1409
 
         x++, ptr_statement= ptr_statement->next)
 
1914
         x++, ptr_statement= ptr_statement->getNext())
1410
1915
    {
1411
 
      ptr_statement->next= build_insert_string();
 
1916
      ptr_statement->setNext(build_insert_string());
1412
1917
    }
1413
1918
 
1414
1919
    if (verbose >= 2)
1420
1925
    query_statements_count=
1421
1926
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1422
1927
 
1423
 
    query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
1928
    query_statements= (Statement **)malloc(sizeof(Statement *) * query_statements_count);
1424
1929
    if (query_statements == NULL)
1425
1930
    {
1426
1931
      fprintf(stderr, "Memory Allocation error in Building Query Statements\n");
1427
1932
      exit(1);
1428
1933
    }
1429
 
    memset(query_statements, 0, sizeof(statement *) * query_statements_count);
 
1934
    memset(query_statements, 0, sizeof(Statement *) * query_statements_count);
1430
1935
 
1431
1936
    sql_type= query_options;
1432
1937
    do
1433
1938
    {
1434
 
      if (sql_type->string[0] == 'r')
 
1939
      if (sql_type->getString()[0] == 'r')
1435
1940
      {
1436
1941
        if (verbose >= 2)
1437
1942
          printf("Generating SELECT Statements for Auto\n");
1439
1944
        query_statements[sql_type_count]= build_select_string(false);
1440
1945
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1441
1946
             x < auto_generate_sql_unique_query_number;
1442
 
             x++, ptr_statement= ptr_statement->next)
 
1947
             x++, ptr_statement= ptr_statement->getNext())
1443
1948
        {
1444
 
          ptr_statement->next= build_select_string(false);
 
1949
          ptr_statement->setNext(build_select_string(false));
1445
1950
        }
1446
1951
      }
1447
 
      else if (sql_type->string[0] == 'k')
 
1952
      else if (sql_type->getString()[0] == 'k')
1448
1953
      {
1449
1954
        if (verbose >= 2)
1450
1955
          printf("Generating SELECT for keys Statements for Auto\n");
1461
1966
        query_statements[sql_type_count]= build_select_string(true);
1462
1967
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1463
1968
             x < auto_generate_sql_unique_query_number;
1464
 
             x++, ptr_statement= ptr_statement->next)
 
1969
             x++, ptr_statement= ptr_statement->getNext())
1465
1970
        {
1466
 
          ptr_statement->next= build_select_string(true);
 
1971
          ptr_statement->setNext(build_select_string(true));
1467
1972
        }
1468
1973
      }
1469
 
      else if (sql_type->string[0] == 'w')
 
1974
      else if (sql_type->getString()[0] == 'w')
1470
1975
      {
1471
1976
        /*
1472
1977
          We generate a number of strings in case the engine is
1478
1983
        query_statements[sql_type_count]= build_insert_string();
1479
1984
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1480
1985
             x < auto_generate_sql_unique_query_number;
1481
 
             x++, ptr_statement= ptr_statement->next)
 
1986
             x++, ptr_statement= ptr_statement->getNext())
1482
1987
        {
1483
 
          ptr_statement->next= build_insert_string();
 
1988
          ptr_statement->setNext(build_insert_string());
1484
1989
        }
1485
1990
      }
1486
 
      else if (sql_type->string[0] == 'u')
 
1991
      else if (sql_type->getString()[0] == 'u')
1487
1992
      {
1488
1993
        if ( auto_generate_sql_autoincrement == false &&
1489
1994
             auto_generate_sql_guid_primary == false)
1497
2002
        query_statements[sql_type_count]= build_update_string();
1498
2003
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1499
2004
             x < auto_generate_sql_unique_query_number;
1500
 
             x++, ptr_statement= ptr_statement->next)
 
2005
             x++, ptr_statement= ptr_statement->getNext())
1501
2006
        {
1502
 
          ptr_statement->next= build_update_string();
 
2007
          ptr_statement->setNext(build_update_string());
1503
2008
        }
1504
2009
      }
1505
2010
      else /* Mixed mode is default */
1513
2018
        */
1514
2019
        for (ptr_statement= query_statements[sql_type_count], x= 0;
1515
2020
             x < auto_generate_sql_unique_query_number;
1516
 
             x++, ptr_statement= ptr_statement->next)
 
2021
             x++, ptr_statement= ptr_statement->getNext())
1517
2022
        {
1518
2023
          if (coin)
1519
2024
          {
1520
 
            ptr_statement->next= build_insert_string();
 
2025
            ptr_statement->setNext(build_insert_string());
1521
2026
            coin= 0;
1522
2027
          }
1523
2028
          else
1524
2029
          {
1525
 
            ptr_statement->next= build_select_string(true);
 
2030
            ptr_statement->setNext(build_select_string(true));
1526
2031
            coin= 1;
1527
2032
          }
1528
2033
        }
1529
2034
      }
1530
2035
      sql_type_count++;
1531
 
    } while (sql_type ? (sql_type= sql_type->next) : 0);
 
2036
    } while (sql_type ? (sql_type= sql_type->getNext()) : 0);
1532
2037
  }
1533
2038
  else
1534
2039
  {
1580
2085
      query_statements_count=
1581
2086
        parse_option("default", &query_options, ',');
1582
2087
 
1583
 
      query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
2088
      query_statements= (Statement **)malloc(sizeof(Statement *) * query_statements_count);
1584
2089
      if (query_statements == NULL)
1585
2090
      {
1586
2091
        fprintf(stderr, "Memory Allocation error in option processing\n");
1587
2092
        exit(1);
1588
2093
      }
1589
 
      memset(query_statements, 0, sizeof(statement *) * query_statements_count); 
 
2094
      memset(query_statements, 0, sizeof(Statement *) * query_statements_count); 
1590
2095
    }
1591
2096
 
1592
2097
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1773
2278
 
1774
2279
 
1775
2280
static int
1776
 
generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt)
 
2281
generate_primary_key_list(drizzle_con_st *con, OptionString *engine_stmt)
1777
2282
{
1778
2283
  drizzle_result_st result;
1779
2284
  drizzle_row_t row;
1785
2290
    of the server during load runs.
1786
2291
  */
1787
2292
  if (opt_only_print || (engine_stmt &&
1788
 
                         strstr(engine_stmt->string, "blackhole")))
 
2293
                         strstr(engine_stmt->getString(), "blackhole")))
1789
2294
  {
1790
2295
    primary_keys_number_of= 1;
1791
2296
    primary_keys= (char **)malloc((sizeof(char *) *
1872
2377
}
1873
2378
 
1874
2379
static int
1875
 
create_schema(drizzle_con_st *con, const char *db, statement *stmt,
1876
 
              option_string *engine_stmt, stats *sptr)
 
2380
create_schema(drizzle_con_st *con, const char *db, Statement *stmt,
 
2381
              OptionString *engine_stmt, Stats *sptr)
1877
2382
{
1878
2383
  char query[HUGE_STRING_LENGTH];
1879
 
  statement *ptr;
1880
 
  statement *after_create;
 
2384
  Statement *ptr;
 
2385
  Statement *after_create;
1881
2386
  int len;
1882
2387
  uint64_t count;
1883
2388
  struct timeval start_time, end_time;
1898
2403
  }
1899
2404
  else
1900
2405
  {
1901
 
    sptr->create_count++;
 
2406
    sptr->setCreateCount(sptr->getCreateCount()+1);
1902
2407
  }
1903
2408
 
1904
2409
  if (opt_only_print)
1922
2427
      exit(1);
1923
2428
    }
1924
2429
    drizzle_result_free(&result);
1925
 
    sptr->create_count++;
 
2430
    sptr->setCreateCount(sptr->getCreateCount()+1);
1926
2431
  }
1927
2432
 
1928
2433
  if (engine_stmt)
1929
2434
  {
1930
2435
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1931
 
                  engine_stmt->string);
 
2436
                  engine_stmt->getString());
1932
2437
    if (run_query(con, NULL, query, len))
1933
2438
    {
1934
2439
      fprintf(stderr,"%s: Cannot set default engine: %s\n", internal::my_progname,
1935
2440
              drizzle_con_error(con));
1936
2441
      exit(1);
1937
2442
    }
1938
 
    sptr->create_count++;
 
2443
    sptr->setCreateCount(sptr->getCreateCount()+1);
1939
2444
  }
1940
2445
 
1941
2446
  count= 0;
1942
2447
  after_create= stmt;
1943
2448
 
1944
2449
limit_not_met:
1945
 
  for (ptr= after_create; ptr && ptr->length; ptr= ptr->next, count++)
 
2450
  for (ptr= after_create; ptr && ptr->getLength(); ptr= ptr->getNext(), count++)
1946
2451
  {
1947
2452
    if (auto_generate_sql && ( auto_generate_sql_number == count))
1948
2453
      break;
1949
2454
 
1950
 
    if (engine_stmt && engine_stmt->option && ptr->type == CREATE_TABLE_TYPE)
 
2455
    if (engine_stmt && engine_stmt->getOption() && ptr->getType() == CREATE_TABLE_TYPE)
1951
2456
    {
1952
2457
      char buffer[HUGE_STRING_LENGTH];
1953
2458
 
1954
 
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1955
 
               engine_stmt->option);
 
2459
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->getString(),
 
2460
               engine_stmt->getOption());
1956
2461
      if (run_query(con, NULL, buffer, strlen(buffer)))
1957
2462
      {
1958
2463
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1959
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
2464
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1960
2465
        if (!opt_ignore_sql_errors)
1961
2466
          exit(1);
1962
2467
      }
1963
 
      sptr->create_count++;
 
2468
      sptr->setCreateCount(sptr->getCreateCount()+1);
1964
2469
    }
1965
2470
    else
1966
2471
    {
1967
 
      if (run_query(con, NULL, ptr->string, ptr->length))
 
2472
      if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
1968
2473
      {
1969
2474
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1970
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
2475
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
1971
2476
        if (!opt_ignore_sql_errors)
1972
2477
          exit(1);
1973
2478
      }
1974
 
      sptr->create_count++;
 
2479
      sptr->setCreateCount(sptr->getCreateCount()+1);
1975
2480
    }
1976
2481
  }
1977
2482
 
1978
2483
  if (auto_generate_sql && (auto_generate_sql_number > count ))
1979
2484
  {
1980
2485
    /* Special case for auto create, we don't want to create tables twice */
1981
 
    after_create= stmt->next;
 
2486
    after_create= stmt->getNext();
1982
2487
    goto limit_not_met;
1983
2488
  }
1984
2489
 
1985
2490
  gettimeofday(&end_time, NULL);
1986
2491
 
1987
 
  sptr->create_timing= timedif(end_time, start_time);
 
2492
  sptr->setCreateTiming(timedif(end_time, start_time));
1988
2493
 
1989
2494
  return(0);
1990
2495
}
2010
2515
}
2011
2516
 
2012
2517
static int
2013
 
run_statements(drizzle_con_st *con, statement *stmt)
 
2518
run_statements(drizzle_con_st *con, Statement *stmt)
2014
2519
{
2015
 
  statement *ptr;
 
2520
  Statement *ptr;
2016
2521
 
2017
 
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
 
2522
  for (ptr= stmt; ptr && ptr->getLength(); ptr= ptr->getNext())
2018
2523
  {
2019
 
    if (run_query(con, NULL, ptr->string, ptr->length))
 
2524
    if (run_query(con, NULL, ptr->getString(), ptr->getLength()))
2020
2525
    {
2021
2526
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2022
 
              internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
 
2527
              internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(con));
2023
2528
      exit(1);
2024
2529
    }
2025
2530
  }
2028
2533
}
2029
2534
 
2030
2535
static int
2031
 
run_scheduler(stats *sptr, statement **stmts, uint32_t concur, uint64_t limit)
 
2536
run_scheduler(Stats *sptr, Statement **stmts, uint32_t concur, uint64_t limit)
2032
2537
{
2033
2538
  uint32_t x;
2034
2539
  uint32_t y;
2035
2540
  unsigned int real_concurrency;
2036
2541
  struct timeval start_time, end_time;
2037
 
  option_string *sql_type;
2038
 
  thread_context *con;
 
2542
  OptionString *sql_type;
 
2543
  ThreadContext *con;
2039
2544
  pthread_t mainthread;            /* Thread descriptor */
2040
2545
  pthread_attr_t attr;          /* Thread attributes */
2041
2546
 
2055
2560
 
2056
2561
  for (y= 0, sql_type= query_options;
2057
2562
       y < query_statements_count;
2058
 
       y++, sql_type= sql_type->next)
 
2563
       y++, sql_type= sql_type->getNext())
2059
2564
  {
2060
2565
    unsigned int options_loop= 1;
2061
2566
 
2062
 
    if (sql_type->option)
 
2567
    if (sql_type->getOption())
2063
2568
    {
2064
 
      options_loop= strtol(sql_type->option,
 
2569
      options_loop= strtol(sql_type->getOption(),
2065
2570
                           (char **)NULL, 10);
2066
2571
      options_loop= options_loop ? options_loop : 1;
2067
2572
    }
2069
2574
    while (options_loop--)
2070
2575
      for (x= 0; x < concur; x++)
2071
2576
      {
2072
 
        con= (thread_context *)malloc(sizeof(thread_context));
 
2577
        con= (ThreadContext *)malloc(sizeof(ThreadContext));
2073
2578
        if (con == NULL)
2074
2579
        {
2075
2580
          fprintf(stderr, "Memory Allocation error in scheduler\n");
2076
2581
          exit(1);
2077
2582
        }
2078
 
        con->stmt= stmts[y];
2079
 
        con->limit= limit;
 
2583
        con->setStmt(stmts[y]);
 
2584
        con->setLimit(limit);
2080
2585
 
2081
2586
        real_concurrency++;
2082
2587
        /* now you create the thread */
2134
2639
  gettimeofday(&end_time, NULL);
2135
2640
 
2136
2641
 
2137
 
  sptr->timing= timedif(end_time, start_time);
2138
 
  sptr->users= concur;
2139
 
  sptr->real_users= real_concurrency;
2140
 
  sptr->rows= limit;
 
2642
  sptr->setTiming(timedif(end_time, start_time));
 
2643
  sptr->setUsers(concur);
 
2644
  sptr->setRealUsers(real_concurrency);
 
2645
  sptr->setRows(limit);
2141
2646
 
2142
2647
  return(0);
2143
2648
}
2181
2686
  drizzle_con_st con;
2182
2687
  drizzle_result_st result;
2183
2688
  drizzle_row_t row;
2184
 
  statement *ptr;
2185
 
  thread_context *ctx= (thread_context *)p;
 
2689
  Statement *ptr;
 
2690
  ThreadContext *ctx= (ThreadContext *)p;
2186
2691
 
2187
2692
  pthread_mutex_lock(&sleeper_mutex);
2188
2693
  while (master_wakeup)
2202
2707
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2203
2708
 
2204
2709
limit_not_met:
2205
 
  for (ptr= ctx->stmt, detach_counter= 0;
2206
 
       ptr && ptr->length;
2207
 
       ptr= ptr->next, detach_counter++)
 
2710
  for (ptr= ctx->getStmt(), detach_counter= 0;
 
2711
       ptr && ptr->getLength();
 
2712
       ptr= ptr->getNext(), detach_counter++)
2208
2713
  {
2209
2714
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2210
2715
    {
2215
2720
    /*
2216
2721
      We have to execute differently based on query type. This should become a function.
2217
2722
    */
2218
 
    if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
2219
 
        (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
 
2723
    if ((ptr->getType() == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
2724
        (ptr->getType() == SELECT_TYPE_REQUIRES_PREFIX))
2220
2725
    {
2221
2726
      int length;
2222
2727
      unsigned int key_val;
2239
2744
        assert(key);
2240
2745
 
2241
2746
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2242
 
                         (int)ptr->length, ptr->string, key);
 
2747
                         (int)ptr->getLength(), ptr->getString(), key);
2243
2748
 
2244
2749
        if (run_query(&con, &result, buffer, length))
2245
2750
        {
2251
2756
    }
2252
2757
    else
2253
2758
    {
2254
 
      if (run_query(&con, &result, ptr->string, ptr->length))
 
2759
      if (run_query(&con, &result, ptr->getString(), ptr->getLength()))
2255
2760
      {
2256
2761
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2257
 
                internal::my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
 
2762
                internal::my_progname, (uint32_t)ptr->getLength(), ptr->getString(), drizzle_con_error(&con));
2258
2763
        exit(1);
2259
2764
      }
2260
2765
    }
2278
2783
      goto end;
2279
2784
 
2280
2785
    /* 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)
 
2786
    if (ctx->getLimit() && queries == ctx->getLimit() && timer_alarm == false)
2282
2787
      goto end;
2283
2788
  }
2284
2789
 
2285
2790
  if (opt_timer_length && timer_alarm == true)
2286
2791
    goto limit_not_met;
2287
2792
 
2288
 
  if (ctx->limit && queries < ctx->limit)
 
2793
  if (ctx->getLimit() && queries < ctx->getLimit())
2289
2794
    goto limit_not_met;
2290
2795
 
2291
2796
 
2310
2815
  on variables.
2311
2816
*/
2312
2817
uint
2313
 
parse_option(const char *origin, option_string **stmt, char delm)
 
2818
parse_option(const char *origin, OptionString **stmt, char delm)
2314
2819
{
2315
2820
  char *string;
2316
2821
  char *begin_ptr;
2317
2822
  char *end_ptr;
2318
 
  option_string **sptr= stmt;
2319
 
  option_string *tmp;
 
2823
  OptionString **sptr= stmt;
 
2824
  OptionString *tmp;
2320
2825
  uint32_t length= strlen(origin);
2321
2826
  uint32_t count= 0; /* We know that there is always one */
2322
2827
 
2323
2828
  end_ptr= (char *)origin + length;
2324
2829
 
2325
 
  tmp= *sptr= (option_string *)malloc(sizeof(option_string));
 
2830
  tmp= *sptr= (OptionString *)malloc(sizeof(OptionString));
2326
2831
  if (tmp == NULL)
2327
2832
  {
2328
2833
    fprintf(stderr,"Error allocating memory while parsing options\n");
2329
2834
    exit(1);
2330
2835
  }
2331
 
  memset(tmp, 0, sizeof(option_string));
 
2836
  memset(tmp, 0, sizeof(OptionString));
2332
2837
 
2333
2838
  for (begin_ptr= (char *)origin;
2334
2839
       begin_ptr != end_ptr;
2335
 
       tmp= tmp->next)
 
2840
       tmp= tmp->getNext())
2336
2841
  {
2337
2842
    char buffer[HUGE_STRING_LENGTH];
2338
2843
    char *buffer_ptr;
2360
2865
      buffer_ptr++;
2361
2866
 
2362
2867
      /* Move past the : and the first string */
2363
 
      tmp->option_length= strlen(buffer_ptr);
2364
 
      tmp->option= (char *)malloc(tmp->option_length + 1);
2365
 
      if (tmp->option == NULL)
 
2868
      tmp->setOptionLength(strlen(buffer_ptr));
 
2869
      tmp->setOption((char *)malloc(tmp->getOptionLength() + 1));
 
2870
      if (tmp->getOption() == NULL)
2366
2871
      {
2367
2872
        fprintf(stderr,"Error allocating memory while parsing options\n");
2368
2873
        exit(1);
2369
2874
      }
2370
 
      memcpy(tmp->option, buffer_ptr, tmp->option_length);
2371
 
      tmp->option[tmp->option_length]= 0; 
 
2875
      memcpy(tmp->getOption(), buffer_ptr, tmp->getOptionLength());
 
2876
      tmp->setOption(tmp->getOptionLength(),0); 
2372
2877
    }
2373
2878
 
2374
 
    tmp->length= strlen(buffer);
2375
 
    tmp->string= strdup(buffer);
2376
 
    if (tmp->string == NULL)
 
2879
    tmp->setLength(strlen(buffer));
 
2880
    tmp->setString(strdup(buffer));
 
2881
    if (tmp->getString() == NULL)
2377
2882
    {
2378
2883
      fprintf(stderr,"Error allocating memory while parsing options\n");
2379
2884
      exit(1);
2386
2891
 
2387
2892
    if (begin_ptr != end_ptr)
2388
2893
    {
2389
 
      tmp->next= (option_string *)malloc(sizeof(option_string));
2390
 
      if (tmp->next == NULL)
 
2894
      tmp->setNext((OptionString *)malloc(sizeof(OptionString)));
 
2895
      if (tmp->getNext() == NULL)
2391
2896
      {
2392
2897
        fprintf(stderr,"Error allocating memory while parsing options\n");
2393
2898
        exit(1);
2394
2899
      }
2395
 
      memset(tmp->next, 0, sizeof(option_string));
 
2900
      memset(tmp->getNext(), 0, sizeof(OptionString));
2396
2901
    }
2397
2902
    
2398
2903
  }
2406
2911
  parse_option.
2407
2912
*/
2408
2913
uint
2409
 
parse_delimiter(const char *script, statement **stmt, char delm)
 
2914
parse_delimiter(const char *script, Statement **stmt, char delm)
2410
2915
{
2411
2916
  char *retstr;
2412
2917
  char *ptr= (char *)script;
2413
 
  statement **sptr= stmt;
2414
 
  statement *tmp;
 
2918
  Statement **sptr= stmt;
 
2919
  Statement *tmp;
2415
2920
  uint32_t length= strlen(script);
2416
2921
  uint32_t count= 0; /* We know that there is always one */
2417
2922
 
2418
 
  for (tmp= *sptr= (statement *)calloc(1, sizeof(statement));
 
2923
  for (tmp= *sptr= (Statement *)calloc(1, sizeof(Statement));
2419
2924
       (retstr= strchr(ptr, delm));
2420
 
       tmp->next=  (statement *)calloc(1, sizeof(statement)),
2421
 
       tmp= tmp->next)
 
2925
       tmp->setNext((Statement *)calloc(1, sizeof(Statement))),
 
2926
       tmp= tmp->getNext())
2422
2927
  {
2423
2928
    if (tmp == NULL)
2424
2929
    {
2427
2932
    }
2428
2933
 
2429
2934
    count++;
2430
 
    tmp->length= (size_t)(retstr - ptr);
2431
 
    tmp->string= (char *)malloc(tmp->length + 1);
 
2935
    tmp->setLength((size_t)(retstr - ptr));
 
2936
    tmp->setString((char *)malloc(tmp->getLength() + 1));
2432
2937
 
2433
 
    if (tmp->string == NULL)
 
2938
    if (tmp->getString() == NULL)
2434
2939
    {
2435
2940
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2436
2941
      exit(1);
2437
2942
    }
2438
2943
 
2439
 
    memcpy(tmp->string, ptr, tmp->length);
2440
 
    tmp->string[tmp->length]= 0;
 
2944
    memcpy(tmp->getString(), ptr, tmp->getLength());
 
2945
    tmp->setString(tmp->getLength(), 0);
2441
2946
    ptr+= retstr - ptr + 1;
2442
2947
    if (isspace(*ptr))
2443
2948
      ptr++;
2445
2950
 
2446
2951
  if (ptr != script+length)
2447
2952
  {
2448
 
    tmp->length= (size_t)((script + length) - ptr);
2449
 
    tmp->string= (char *)malloc(tmp->length + 1);
2450
 
    if (tmp->string == NULL)
 
2953
    tmp->setLength((size_t)((script + length) - ptr));
 
2954
    tmp->setString((char *)malloc(tmp->getLength() + 1));
 
2955
    if (tmp->getString() == NULL)
2451
2956
    {
2452
2957
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
2453
2958
      exit(1);
2454
2959
    }
2455
 
    memcpy(tmp->string, ptr, tmp->length);
2456
 
    tmp->string[tmp->length]= 0;
 
2960
    memcpy(tmp->getString(), ptr, tmp->getLength());
 
2961
    tmp->setString(tmp->getLength(),0);
2457
2962
    count++;
2458
2963
  }
2459
2964
 
2494
2999
}
2495
3000
 
2496
3001
void
2497
 
print_conclusions(conclusions *con)
 
3002
print_conclusions(Conclusions *con)
2498
3003
{
2499
3004
  printf("Benchmark\n");
2500
 
  if (con->engine)
2501
 
    printf("\tRunning for engine %s\n", con->engine);
 
3005
  if (con->getEngine())
 
3006
    printf("\tRunning for engine %s\n", con->getEngine());
2502
3007
  if (opt_label || opt_auto_generate_sql_type)
2503
3008
  {
2504
3009
    const char *ptr= opt_auto_generate_sql_type ? opt_auto_generate_sql_type : "query";
2505
3010
    printf("\tLoad: %s\n", opt_label ? opt_label : ptr);
2506
3011
  }
2507
3012
  printf("\tAverage Time took to generate schema and initial data: %ld.%03ld seconds\n",
2508
 
         con->create_avg_timing / 1000, con->create_avg_timing % 1000);
 
3013
         con->getCreateAvgTiming() / 1000, con->getCreateAvgTiming() % 1000);
2509
3014
  printf("\tAverage number of seconds to run all queries: %ld.%03ld seconds\n",
2510
 
         con->avg_timing / 1000, con->avg_timing % 1000);
 
3015
         con->getAvgTiming() / 1000, con->getAvgTiming() % 1000);
2511
3016
  printf("\tMinimum number of seconds to run all queries: %ld.%03ld seconds\n",
2512
 
         con->min_timing / 1000, con->min_timing % 1000);
 
3017
         con->getMinTiming() / 1000, con->getMinTiming() % 1000);
2513
3018
  printf("\tMaximum number of seconds to run all queries: %ld.%03ld seconds\n",
2514
 
         con->max_timing / 1000, con->max_timing % 1000);
 
3019
         con->getMaxTiming() / 1000, con->getMaxTiming() % 1000);
2515
3020
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2516
 
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2517
 
  printf("\tStandard Deviation: %ld.%03ld\n", con->std_dev / 1000, con->std_dev % 1000);
2518
 
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->create_count);
 
3021
         con->getSumOfTime() / 1000, con->getSumOfTime() % 1000);
 
3022
  printf("\tStandard Deviation: %ld.%03ld\n", con->getStdDev() / 1000, con->getStdDev() % 1000);
 
3023
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->getCreateCount());
2519
3024
  printf("\tNumber of clients running queries: %u/%u\n",
2520
 
         con->users, con->real_users);
 
3025
         con->getUsers(), con->getRealUsers());
2521
3026
  printf("\tNumber of times test was run: %u\n", iterations);
2522
 
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->avg_rows);
 
3027
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->getAvgRows());
2523
3028
  printf("\n");
2524
3029
}
2525
3030
 
2526
3031
void
2527
 
print_conclusions_csv(conclusions *con)
 
3032
print_conclusions_csv(Conclusions *con)
2528
3033
{
2529
3034
  unsigned int x;
2530
3035
  char buffer[HUGE_STRING_LENGTH];
2563
3068
  snprintf(buffer, HUGE_STRING_LENGTH,
2564
3069
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
2565
3070
           "%u,%u,%u,%"PRIu64"\n",
2566
 
           con->engine ? con->engine : "", /* Storage engine we ran against */
 
3071
           con->getEngine() ? con->getEngine() : "", /* Storage engine we ran against */
2567
3072
           label_buffer, /* Load type */
2568
 
           con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
2569
 
           con->min_timing / 1000, con->min_timing % 1000, /* Min time */
2570
 
           con->max_timing / 1000, con->max_timing % 1000, /* Max time */
2571
 
           con->sum_of_time / 1000, con->sum_of_time % 1000, /* Total time */
2572
 
           con->std_dev / 1000, con->std_dev % 1000, /* Standard Deviation */
 
3073
           con->getAvgTiming() / 1000, con->getAvgTiming() % 1000, /* Time to load */
 
3074
           con->getMinTiming() / 1000, con->getMinTiming() % 1000, /* Min time */
 
3075
           con->getMaxTiming() / 1000, con->getMaxTiming() % 1000, /* Max time */
 
3076
           con->getSumOfTime() / 1000, con->getSumOfTime() % 1000, /* Total time */
 
3077
           con->getStdDev() / 1000, con->getStdDev() % 1000, /* Standard Deviation */
2573
3078
           iterations, /* Iterations */
2574
 
           con->users, /* Children used max_timing */
2575
 
           con->real_users, /* Children used max_timing */
2576
 
           con->avg_rows  /* Queries run */
 
3079
           con->getUsers(), /* Children used max_timing */
 
3080
           con->getRealUsers(), /* Children used max_timing */
 
3081
           con->getAvgRows()  /* Queries run */
2577
3082
           );
2578
3083
  internal::my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2579
3084
}
2580
3085
 
2581
3086
void
2582
 
generate_stats(conclusions *con, option_string *eng, stats *sptr)
 
3087
generate_stats(Conclusions *con, OptionString *eng, Stats *sptr)
2583
3088
{
2584
 
  stats *ptr;
 
3089
  Stats *ptr;
2585
3090
  unsigned int x;
2586
3091
 
2587
 
  con->min_timing= sptr->timing;
2588
 
  con->max_timing= sptr->timing;
2589
 
  con->min_rows= sptr->rows;
2590
 
  con->max_rows= sptr->rows;
 
3092
  con->setMinTiming(sptr->getTiming());
 
3093
  con->setMaxTiming(sptr->getTiming());
 
3094
  con->setMinRows(sptr->getRows());
 
3095
  con->setMaxRows(sptr->getRows());
2591
3096
 
2592
3097
  /* At the moment we assume uniform */
2593
 
  con->users= sptr->users;
2594
 
  con->real_users= sptr->real_users;
2595
 
  con->avg_rows= sptr->rows;
 
3098
  con->setUsers(sptr->getUsers());
 
3099
  con->setRealUsers(sptr->getRealUsers());
 
3100
  con->setAvgRows(sptr->getRows());
2596
3101
 
2597
3102
  /* With no next, we know it is the last element that was malloced */
2598
3103
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2599
3104
  {
2600
 
    con->avg_timing+= ptr->timing;
 
3105
    con->setAvgTiming(ptr->getTiming()+con->getAvgTiming());
2601
3106
 
2602
 
    if (ptr->timing > con->max_timing)
2603
 
      con->max_timing= ptr->timing;
2604
 
    if (ptr->timing < con->min_timing)
2605
 
      con->min_timing= ptr->timing;
 
3107
    if (ptr->getTiming() > con->getMaxTiming())
 
3108
      con->setMaxTiming(ptr->getTiming());
 
3109
    if (ptr->getTiming() < con->getMinTiming())
 
3110
      con->setMinTiming(ptr->getTiming());
2606
3111
  }
2607
 
  con->sum_of_time= con->avg_timing;
2608
 
  con->avg_timing= con->avg_timing/iterations;
 
3112
  con->setSumOfTime(con->getAvgTiming());
 
3113
  con->setAvgTiming(con->getAvgTiming()/iterations);
2609
3114
 
2610
 
  if (eng && eng->string)
2611
 
    con->engine= eng->string;
 
3115
  if (eng && eng->getString())
 
3116
    con->setEngine(eng->getString());
2612
3117
  else
2613
 
    con->engine= NULL;
 
3118
    con->setEngine(NULL);
2614
3119
 
2615
3120
  standard_deviation(con, sptr);
2616
3121
 
2617
3122
  /* Now we do the create time operations */
2618
 
  con->create_min_timing= sptr->create_timing;
2619
 
  con->create_max_timing= sptr->create_timing;
 
3123
  con->setCreateMinTiming(sptr->getCreateTiming());
 
3124
  con->setCreateMaxTiming(sptr->getCreateTiming());
2620
3125
 
2621
3126
  /* At the moment we assume uniform */
2622
 
  con->create_count= sptr->create_count;
 
3127
  con->setCreateCount(sptr->getCreateCount());
2623
3128
 
2624
3129
  /* With no next, we know it is the last element that was malloced */
2625
3130
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2626
3131
  {
2627
 
    con->create_avg_timing+= ptr->create_timing;
 
3132
    con->setCreateAvgTiming(ptr->getCreateTiming()+con->getCreateAvgTiming());
2628
3133
 
2629
 
    if (ptr->create_timing > con->create_max_timing)
2630
 
      con->create_max_timing= ptr->create_timing;
2631
 
    if (ptr->create_timing < con->create_min_timing)
2632
 
      con->create_min_timing= ptr->create_timing;
 
3134
    if (ptr->getCreateTiming() > con->getCreateMaxTiming())
 
3135
      con->setCreateMaxTiming(ptr->getCreateTiming());
 
3136
    if (ptr->getCreateTiming() < con->getCreateMinTiming())
 
3137
      con->setCreateMinTiming(ptr->getCreateTiming());
2633
3138
  }
2634
 
  con->create_avg_timing= con->create_avg_timing/iterations;
 
3139
  con->setCreateAvgTiming(con->getCreateAvgTiming()/iterations);
2635
3140
}
2636
3141
 
2637
3142
void
2638
 
option_cleanup(option_string *stmt)
 
3143
option_cleanup(OptionString *stmt)
2639
3144
{
2640
 
  option_string *ptr, *nptr;
 
3145
  OptionString *ptr, *nptr;
2641
3146
  if (!stmt)
2642
3147
    return;
2643
3148
 
2644
3149
  for (ptr= stmt; ptr; ptr= nptr)
2645
3150
  {
2646
 
    nptr= ptr->next;
2647
 
    if (ptr->string)
2648
 
      free(ptr->string);
2649
 
    if (ptr->option)
2650
 
      free(ptr->option);
 
3151
    nptr= ptr->getNext();
 
3152
    if (ptr->getString())
 
3153
      free(ptr->getString());
 
3154
    if (ptr->getOption())
 
3155
      free(ptr->getOption());
2651
3156
    free(ptr);
2652
3157
  }
2653
3158
}
2654
3159
 
2655
3160
void
2656
 
statement_cleanup(statement *stmt)
 
3161
statement_cleanup(Statement *stmt)
2657
3162
{
2658
 
  statement *ptr, *nptr;
 
3163
  Statement *ptr, *nptr;
2659
3164
  if (!stmt)
2660
3165
    return;
2661
3166
 
2662
3167
  for (ptr= stmt; ptr; ptr= nptr)
2663
3168
  {
2664
 
    nptr= ptr->next;
2665
 
    if (ptr->string)
2666
 
      free(ptr->string);
 
3169
    nptr= ptr->getNext();
 
3170
    if (ptr->getString())
 
3171
      free(ptr->getString());
2667
3172
    free(ptr);
2668
3173
  }
2669
3174
}
2723
3228
}
2724
3229
 
2725
3230
void
2726
 
standard_deviation (conclusions *con, stats *sptr)
 
3231
standard_deviation (Conclusions *con, Stats *sptr)
2727
3232
{
2728
3233
  unsigned int x;
2729
3234
  long int sum_of_squares;
2730
3235
  double the_catch;
2731
 
  stats *ptr;
 
3236
  Stats *ptr;
2732
3237
 
2733
3238
  if (iterations == 1 || iterations == 0)
2734
3239
  {
2735
 
    con->std_dev= 0;
 
3240
    con->setStdDev(0);
2736
3241
    return;
2737
3242
  }
2738
3243
 
2740
3245
  {
2741
3246
    long int deviation;
2742
3247
 
2743
 
    deviation= ptr->timing - con->avg_timing;
 
3248
    deviation= ptr->getTiming() - con->getAvgTiming();
2744
3249
    sum_of_squares+= deviation*deviation;
2745
3250
  }
2746
3251
 
2747
3252
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
2748
 
  con->std_dev= (long int)the_catch;
 
3253
  con->setStdDev((long int)the_catch);
2749
3254
}