-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtptbm.c
3999 lines (3609 loc) · 132 KB
/
tptbm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Universal Permissive License v 1.0 as shown
* at http://oss.oracle.com/licenses/upl
*/
/* This source is best displayed with a tabstop of 4 */
#ifdef WIN32
#include <windows.h>
#include <sys/timeb.h>
#include <time.h>
#include <process.h>
#include <winbase.h>
#else
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <time.h>
#include <sys/time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <errno.h>
#include <sqlunix.h>
#endif
#include <stdlib.h>
#include <sql.h>
#include <sqlext.h>
#include <stdio.h>
#include <math.h>
#include "utils.h"
#include "tt_version.h"
#include "timesten.h"
#include "ttgetopt.h"
#if defined(SCALEOUT)
#if ! defined(ROUTINGAPI)
#define ROUTINGAPI
#else
#undef ROUTINGAPI
#endif /* ! ROUTINGAPI */
#endif /* SCALEOUT */
#if defined(TTCLIENTSERVER) || defined(TTDM)
#define ROUTINGAPI_ALL
#else
#undef ROUTINGAPI_ALL
#endif /* TTCLIENTSERVER || TTDM */
#define VERBOSE_NOMSGS 0
#define VERBOSE_RESULTS 1 /* for results (and err msgs) only */
#define VERBOSE_DFLT 2 /* the default for the cmdline demo */
#define VERBOSE_ALL 3
#define VERBOSE_FIRST VERBOSE_NOMSGS
#define VERBOSE_LAST VERBOSE_ALL
#define XS(str) #str
#define S(str) XS(str)
#define POP_COMMIT_INTVL 1024
#define NO_VALUE -1
#define MIN_KEY 2
#define DBMODE_ID -1
#define DBMODE_NB -1
#define DBMODE_FILLER " "
#define SEL_DBMODE "SELECT descr FROM VPN_USERS WHERE vpn_id = -1 AND vpn_nb = -1"
#define M_CLASSIC 0
#define DBMODE_CLASSIC "CLASSIC"
#if defined(SCALEOUT)
#define MAX_KVALUE 5
#define M_SCALEOUT 1
#define DBMODE_SCALEOUT "SCALEOUT"
#if defined(ROUTINGAPI)
#define M_SCALEOUT_LOCAL 2
#if defined(ROUTINGAPI_ALL)
#define M_SCALEOUT_ROUTING 3
#endif /* ROUTINGAPI_ALL */
#endif /* ROUTINGAPI */
#endif /* SCALEOUT */
#define DFLT_XACT 100000
#define DFLT_SEED 2021
#define DFLT_PROC 1
#define DFLT_RAMPTIME 10
#define DFLT_READS 80
#define DFLT_INSERTS 0
#define DFLT_DELETES 0
#define DFLT_OPS 1
#define DFLT_NODBEXEC 0
#define DFLT_KEY 100
#define DFLT_ISO 1
#define DFLT_RANGE 0
#define DFLT_BUILDONLY 0
#define DFLT_NOBUILD 0
#define DFLT_THROTTLE 0
#define DFLT_INSERT_MOD 1
#define DFLT_PROCID 0
#define PROC_INITIALIZED 0 // base state (not currently used)
#define PROC_READY 1 // P -> C: get ready to begin execution
#define PROC_SET 2 // C -> P: ready for execution
#define PROC_GO 3 // P -> C: start execution
#define PROC_RUNNING 4 // C -> P: executing
#define PROC_STARTBENCH 5 // P -> C: start measuring
#define PROC_MEASURING 6 // C -> P: measuring
#define PROC_STOPBENCH 7 // P -> C: stop measuring
#define PROC_STOPPING 8 // C -> P: stopping
#define PROC_STOP 9 // P -> C: stop
#define PROC_END 10 // C -> P: finished, okay
#define PROC_ERROR 11 // C -> P: finished, ERROR
#define TTCSERVERDSN "TTC_SERVER_DSN="
static char usageStr[] =
"\n"
"This program implements a multi-user throughput benchmark using\n"
#if defined(TTDM)
"both direct connection and client-server connection modes.\n\n"
#else
#if defined(TTCLIENTSERVER)
"client-server connection mode.\n\n"
#else
"direct connection mode.\n\n"
#endif /* TTCLIENTSERVER */
#endif /* TTDM */
"Usage:\n\n"
" %s {-h | -help}\n\n"
" %s [-proc <nprocs>] [-read <nreads>] [-insert <nins>] [-delete <ndels>]\n"
" [{-xact <xacts> | -sec <secs> [-ramp <rsecs> | [-rampu <rusecs>] [-rampd <rdsecs>]]}]\n"
" [-throttle <n>] [-ops <ops>] [-key <keys>] [-range] [-iso <level>] [-seed <seed>]\n"
" [-build] [-nobuild] [-v <level>]"
#ifdef SCALEOUT
#if defined(ROUTINGAPI_ALL)
" [-scaleout [local | routing[/<srvdsn>]]]"
#elif defined(ROUTINGAPI)
" [-scaleout [local]]"
#else
" [-scaleout]"
#endif /* ROUTINGAPI */
#endif /* SCALEOUT */
"\n [<DSN> | -connstr <connection-string>]\n\n";
static char usageStrFull[] =
" -h Prints this message and exits.\n\n"
" -help Same as -h.\n\n"
" -V Prints version number and exits.\n\n"
" -proc <nprocs> Specifies that <nprocs> is the number of concurrent\n"
" processes. The default is " S(DFLT_PROC) ".\n\n"
" -read <nreads> Specifies that <nreads> is the percentage of read-only\n"
" transactions. The default is " S(DFLT_READS) ".\n\n"
" -insert <nins> Specifies that <nins> is the percentage of insert\n"
" transactions. The default is " S(DFLT_INSERTS) ".\n"
" Cannot be used with '-nobuild' or '-sec'\n\n"
" -delete <ndels> Specifies that <ndels> is the percentage of delete\n"
" transactions. The default is " S(DFLT_DELETES) ".\n"
" Cannot be used with '-nobuild' or '-sec'\n\n"
" -xact <xacts> Specifies that <xacts> is the number of transactions\n"
" that each process should run. The default is " S(DFLT_XACT) ".\n"
" Cannot be used with '-sec'\n\n"
" -sec <secs> Specifies that <secs> is the test measurement duration.\n"
" The default is to run in transaction mode (-xact).\n"
" Cannot be used with '-xact'\n\n"
" -ramp <rsecs> Specifies that <rsecs> is the ramp up & down time in\n"
" duration mode (-sec). Default is " S(DFLT_RAMPTIME) ".\n"
" Cannot be used with '-xact'\n\n"
" -rampu <rusecs> Specifies that <rusecs> is the ramp up time in duration\n"
" mode (-sec). Default is " S(DFLT_RAMPTIME) ".\n"
" Cannot be used with '-xact'\n\n"
" -rampd <rdsecs> Specifies that <rdsecs> is the ramp down time in duration\n"
" mode (-sec). Default is " S(DFLT_RAMPTIME) ".\n"
" Cannot be used with '-xact'\n\n"
" -throttle <n> Throttle each process to <n> operations per second.\n"
" Must be > 0. The default is no throttle.\n\n"
" -ops <ops> Operations per transaction. The default is " S(DFLT_OPS) ".\n"
" In the special case where 0 is specified, no commit\n"
" is done. This may be useful for read-only testing.\n\n"
" -key <keys> Specifies the number of records (squared) to initially\n"
" populate in the database. The minimum value is " S(MIN_KEY) "\n"
" and the default is " S(DFLT_KEY) " (" S(DFLT_KEY) "**2 rows). The same\n"
" value should be specified at both build and run time.\n\n"
" -range Use a range index for the primary key instead of a hash\n"
" index. Not relevant with '-nobuild'.\n\n"
" -iso <level> Locking isolation level\n"
" 0 = serializable\n"
" 1 = read-committed (default)\n\n"
" -seed <seed> Specifies that <seed> should be the seed for the\n"
" random number generator. Must be > 0, default is " S(DFLT_SEED) ".\n\n"
" -build Only build the database, do not run the benchmark. Only\n"
#if defined(SCALEOUT)
" the '-key', '-range' and '-scaleout' parameters are\n"
" relevant.\n\n"
#else /* ! SCALEOUT */
" the '-key' and '-range' parameters are relevant.\n\n"
#endif /* ! SCALEOUT */
" -nobuild Only run the benchmark, do not build the database.\n"
" The '-range' parameter is not relevant.\n"
" Cannot be used with '-insert' or '-delete'.\n\n"
#if 0
" -nodbexec Don't perform any of the actual database operations in\n"
" the main benchmark loop. This allows you to get a sense\n"
" for the cost of the 'application overhead'.\n\n"
#endif
#if defined(SCALEOUT)
" -scaleout Run in Scaleout mode. Creates the table with a hash\n"
" distribution and adapts runtime behaviour for Scaleout.\n"
" You must use the same value at build time and run-time.\n\n"
#if defined(ROUTINGAPI)
" local Constrain all data access to be to rows in the locally\n"
" connected database element; each process generates keys\n"
" that it knows refer to rows in the element that it is\n"
" connected to. Only relevant at run-time.\n\n"
#if defined(ROUTINGAPI_ALL)
" routing[/<srvdsn>] Use the routing API to optimize data access. Each\n"
" process maintains a connection to every database\n"
" element and uses the routing API to direct operations\n"
" to an element that it knows contains the target row.\n"
" Normally the server DSN is detected automatically but\n"
" if it is not you can specify it using /<srvdsn>. If\n"
" you do specify /<srvdsn> the value will be used instead\n"
" of any automatically determined value. Only relevant\n"
" at run time. Cannot be used with -ops > 1.\n\n"
#endif /* ROUTINGAPI_ALL */
#endif /* ROUTINGAPI */
#endif /* SCALEOUT */
" -v <level> Verbosity level\n"
" 0 = errors only\n"
" 1 = results only\n"
" 2 = results and some status messages (default)\n"
" 3 = all messages\n\n"
"If no DSN or connection string is specified, the default is\n"
" \"DSN=sampledb;UID=appuser\".\n\n"
"The percentage of update operations is 100 minus the percentages of reads,\n"
"inserts and deletes.\n\n"
"For the most accurate results, use duration mode (-sec) with a measurement\n"
"time of at least several minutes and a ramp time of at least 30 seconds.\n\n";
#define DFLT_DSN DEMODSN
#define DFLT_UID UIDNAME
/* message macros used for all conditional non-error output */
#define tptbm_msg0(str) \
{ \
if (verbose >= VERBOSE_DFLT) \
{ \
fprintf (statusfp, str); \
fflush (statusfp); \
} \
}
#define tptbm_msg1(str, arg1) \
{ \
if (verbose >= VERBOSE_DFLT) \
{ \
fprintf (statusfp, str, arg1); \
fflush (statusfp); \
} \
}
#define tptbm_msg2(str, arg1, arg2) \
{ \
if (verbose >= VERBOSE_DFLT) \
{ \
fprintf (statusfp, str, arg1, arg2); \
fflush (statusfp); \
} \
}
#define tptbm_msg5(str, arg1, arg2, arg3, arg4, arg5) \
{ \
if (verbose >= VERBOSE_DFLT) \
{ \
fprintf (statusfp, str, arg1, arg2, arg3, arg4, arg5); \
fflush (statusfp); \
} \
}
/* Forward declarations */
//void ExecuteTptBm (int seed, int procId);
void ExecuteTptBm (unsigned int seed, int procId);
void erasePassword(volatile char *buf, size_t len);
void getPassword(const char * prompt, const char * uid, char * pswd, size_t len);
int parseConnectionString(
char * connstr,
char * pDSN,
int sDSN,
char * pUID,
int sUID,
char * pPWD,
int sPWD
);
#ifdef WIN32
#define strncasecmp _strnicmp
#define snprintf _snprintf
typedef struct _timeb ttTime;
#define ttGetTime(p) _ftime(p)
tt_ptrint diff_time (ttTime* start,
ttTime* end)
{
return ((end->time - start->time) * 1000 +
(end->millitm - start->millitm));
}
#define tt_yield() Sleep(0)
#else
typedef struct timeval ttTime;
#define ttGetTime(p) gettimeofday(p, NULL)
tt_ptrint diff_time (ttTime* start,
ttTime* end)
{
return ((end->tv_sec - start->tv_sec) * 1000 +
(end->tv_usec - start->tv_usec) / 1000);
}
#include <sched.h>
#define tt_yield() sched_yield()
#endif
#define CACHELINE_SIZE 128 /* ideal for x8664 and big enough for every platform except Itanium */
typedef struct procinfo {
volatile int state;
volatile int nproc;
volatile long pid;
volatile unsigned long xacts;
char pad[CACHELINE_SIZE - (sizeof(int)+sizeof(int)+sizeof(int)+sizeof(unsigned long))];
} procinfo_t;
#if defined(SCALEOUT) && defined(ROUTINGAPI)
/* ODBC routing API */
TTGRIDMAP routingGridMap;
TTGRIDDIST routingHDist;
/* The distribution key has two columns */
SQLSMALLINT routingCTypes[] = { SQL_C_SLONG, SQL_C_SLONG };
SQLSMALLINT routingSQLTypes[] = { SQL_INTEGER, SQL_INTEGER };
SQLLEN routingMaxSizes[] = { sizeof(int), sizeof(int) };
int nElements = 0;
int kFactor = 0;
#if defined(ROUTINGAPI_ALL)
#define MAX_CLIENT_DSN_LEN 256
typedef struct _ttclientdsn {
int elementid;
int repset;
int dataspace;
SQLHDBC hdbc;
SQLHSTMT selstmt;
SQLHSTMT updstmt;
SQLHSTMT insstmt;
SQLHSTMT delstmt;
SQLCHAR clientdsn[MAX_CLIENT_DSN_LEN+1];
} cCliDSN_t;
cCliDSN_t* routingDSNs = NULL;
#endif /* ROUTINGAPI_ALL */
/* End of ODBC routing API */
#endif /* SCALEOUT && ROUTINGAPI*/
/* Global variable declarations */
unsigned int rand_seed = 0; /* seed for the random numbers */
int num_processes = NO_VALUE; /* # of concurrent processes for the test */
int duration = NO_VALUE; /* test duration */
int ramputime = NO_VALUE; /* ramp up time in the duration mode */
int rampdtime = NO_VALUE; /* ramp up time in the duration mode */
int reads = NO_VALUE; /* read percentage */
int inserts = NO_VALUE; /* insert percentage */
int deletes = NO_VALUE; /* delete percentage */
long num_xacts = NO_VALUE; /* # of transactions per process */
int opsperxact = NO_VALUE; /* operations per transaction or 0 for no commit */
int nodbexec = NO_VALUE; /* don't do actual db work in main benchmark loop */
int key_cnt = NO_VALUE; /* number of keys (squared) populated in the datastore */
int isolevel = NO_VALUE; /* isolation level */
int rangeFlag = NO_VALUE; /* if 1 use range index instead of hash */
int verbose = NO_VALUE; /* verbose level */
FILE* statusfp; /* File for status messages */
char dsn[CONN_STR_LEN] = ""; /* ODBC data source */
char* connstr_opt = NULL; /* ODBC connStr from cmd line */
char* input_connStr = NULL; /* connection string to be used */
char connstr[CONN_STR_LEN] = "";
int buildOnly = NO_VALUE; /* Only create/populate */
int noBuild = NO_VALUE; /* Don't create/populate */
int throttle = NO_VALUE; /* throttle to <n> ops / second */
int mode = M_CLASSIC; /* classic vs. scaleout mode */
int insert_mod = NO_VALUE; /* used to prevent multiple inserts clobber */
#if defined(SCALEOUT) && defined(ROUTINGAPI)
int elementid = 0; /* locally connected element id */
int replicasetid = 0; /* locally connected replicaset id */
int dataspaceid = 0; /* locally connected dataspace id */
char * serverdsn = NULL; /* server DSN for routing mode */
#if defined(ROUTINGAPI_ALL)
char * srvdsn = NULL; /* Server DSN from command line */
#endif /* ROUTINGAPI_ALL */
#endif /* SCALEOUT && ROUTINGAPI */
SQLHENV henv = SQL_NULL_HENV; /* ODBC environment handle */
SQLHDBC ghdbc = SQL_NULL_HDBC; /* global ODBC connection handle */
#if defined(SCALEOUT) && defined(ROUTINGAPI)
SQLHDBC rhdbc = SQL_NULL_HDBC; /* routing API connection handle */
#endif /* SCALEOUT && ROUTINGAPI */
#if defined(WIN32)
HANDLE shmHndl; /* handle to shared memory segment */
#else
int shmid; /* shared memory segment id */
#endif
volatile procinfo_t *shmhdr = NULL; /* shared memory segment to sync processes */
int procId = NO_VALUE; /* process # in shared memory array */
int sigReceived; /* zero if no signal received or signum */
/* tmp file used for shmget() key generation */
char keypath[] = "/tmp/tptbmXXXXXX";
#ifdef WIN32
STARTUPINFO sInfo = {8L, NULL, NULL, NULL,
0L, 0L, 0L, 0L, 0L, 0L, 0L,
STARTF_USESHOWWINDOW, SW_HIDE, 0L,
NULL, NULL, NULL, NULL};
PROCESS_INFORMATION pInfo;
#endif
/* The select statement used for the read transaction */
char* select_stmnt = "select directory_nb,last_calling_party,descr from vpn_users "
"where vpn_id = ? and vpn_nb= ?";
/* The update statement used for the write transaction */
char* update_stmnt = "update vpn_users set last_calling_party = ? "
"where vpn_id = ? and vpn_nb = ?";
/* The create table statement */
char* create_stmnt = "CREATE TABLE vpn_users("
"vpn_id TT_INT NOT NULL,"
"vpn_nb TT_INT NOT NULL,"
"directory_nb CHAR(10) NOT NULL,"
"last_calling_party CHAR(10) NOT NULL,"
"descr CHAR(100) NOT NULL,"
"PRIMARY KEY (vpn_id,vpn_nb))";
char * hash_clause = " unique hash on (vpn_id,vpn_nb) pages = %ld";
char * dist_clause = " distribute by hash(vpn_id, vpn_nb)";
char* drop_stmnt = "DROP TABLE vpn_users";
/* The insert statement used to populate the datastore */
char * insert_stmnt = "insert into vpn_users values (?,?,?,?,?)";
/* The delete statement */
char * delete_stmnt = "delete from vpn_users where vpn_id = ? and vpn_nb = ?";
static char cmdname[80]; /* stripped command name */
char connstr_real[CONN_STR_LEN]; /* ODBC Connection String used */
char connstr_no_password[CONN_STR_LEN]; /* Hide password in childs command-line parameters */
char username[MAX_USERNAME_SIZE];
char password[MAX_PASSWORD_SIZE];
char * passwordPrompt = "Enter password for ";
/*********************************************************************
*
* FUNCTION: usage
*
* DESCRIPTION: This function displays the programme usage info.
*
* PARAMETERS: char * progname - program name
*
* RETURNS: Nothing, exits
*
*********************************************************************/
void usage( char * progname, int full )
{
fprintf( stderr, usageStr, progname, progname );
if ( full )
fprintf( stderr, usageStrFull, progname, progname );
exit( 10 );
}
/*********************************************************************
*
* FUNCTION: nameOfMode
*
* DESCRIPTION: Maps a numeric run-time mode to its name.
*
* PARAMETERS: int mode - the runtime mode
* char ** subname - pointer to receive submode name
*
* RETURNS: Name of mode or NULL.
*
*********************************************************************/
char * nameOfMode( int mode, char ** subname )
{
char * tname = NULL;
char * tsubname = NULL;
switch ( mode )
{
case M_CLASSIC:
tname = "CLASSIC";
break;
#if defined(SCALEOUT)
case M_SCALEOUT:
tname = "SCALEOUT";
break;
#if defined(ROUTINGAPI)
case M_SCALEOUT_LOCAL:
tname = "SCALEOUT";
tsubname = "LOCAL";
break;
#if defined(ROUTINGAPI_ALL)
case M_SCALEOUT_ROUTING:
tname = "SCALEOUT";
tsubname = "ROUTING";
break;
#endif /* ROUTINGAPI_ALL */
#endif /* ROUTINGAPI */
#endif /* SCALEOUT */
default:
break;
}
if ( subname != NULL )
*subname = tsubname;
return tname;
}
/*********************************************************************
*
* FUNCTION: isnumeric
*
* DESCRIPTION: Checks if a string represents a valid unsigned
* integer value in the range 0 to 999999999.
*
* PARAMETERS: char * str
*
* RETURNS: -1 = invalid value otherwise the value of the integer
*
*********************************************************************/
int isnumeric( char * str )
{
int val = 0;
if ( (str == NULL) || (*str == '\0') )
return -1;
if ( strlen( str ) > 9 )
return -1;
while ( *str ) {
if ( (*str < '0') || (*str > '9') )
return -1;
val = (val * 10) + (*str++ - '0');
}
return val;
}
/*********************************************************************
*
* FUNCTION: isnumericL
*
* DESCRIPTION: Checks if a string represents a valid unsigned
* integer value in the range 0 to 999999999999999999
*
* PARAMETERS: char * str
*
* RETURNS: -1 = invalid value otherwise the value of the integer
*
*********************************************************************/
long isnumericL( char * str )
{
long val = 0;
if ( (str == NULL) || (*str == '\0') )
return -1;
if ( strlen( str ) > 18 )
return -1;
while ( *str ) {
if ( (*str < '0') || (*str > '9') )
return -1;
val = (val * 10) + (*str++ - '0');
}
return val;
}
/*********************************************************************
*
* FUNCTION: getServerDSN
*
* DESCRIPTION: Extracts the value of TTC_SERVER_DSN from a
* full connection string.
*
* PARAMETERS: char * connstr - the connection string
* char ** dsnval - returned pointer to a malloc'd string
*
* RETURNS: 0 - failure; 1 - success;
*
* NOTES: NONE
*
*********************************************************************/
int getServerDSN( char * connstr, char ** dsnval )
{
char * p;
char * dsn;
p = strstr( connstr, TTCSERVERDSN );
if ( p == NULL )
return 0;
dsn = p + strlen(TTCSERVERDSN);
if ( (*dsn == '\0') || (*dsn == ';') )
return 0;
p = strchr( dsn, ';' );
if ( p != NULL )
*p = '\0';
*dsnval = dsn;
return 1;
}
/*********************************************************************
*
* FUNCTION: parse_args
*
* DESCRIPTION: This function parses the command line arguments
* passed to main(), setting the appropriate global
* variables and issuing a usage message for
* invalid arguments.
*
* PARAMETERS: int argc # of arguments from main()
* char *argv[] arguments from main()
*
* RETURNS: 0 - failure; 1 - success;
*
* NOTES: NONE
*
*********************************************************************/
int parse_args(int argc,
char** argv)
{
int argno = 1;
int pos = 0;
char * p;
ttc_getcmdname(argv[0], cmdname, sizeof(cmdname));
while ( argno < argc )
{
if ( (strcmp(argv[argno], "-h") == 0) ||
(strcmp(argv[argno], "-help") == 0) )
usage( cmdname, 1 );
else
if ( strcmp(argv[argno], "-proc") == 0 ) {
if ( (++argno >= argc) || (num_processes != NO_VALUE) )
usage( cmdname, 0 );
num_processes = isnumeric( argv[argno] );
if ( num_processes <= 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-read") == 0 ) {
if ( (++argno >= argc) || (reads != NO_VALUE) )
usage( cmdname, 0 );
reads = isnumeric( argv[argno] );
if ( (reads < 0) || (reads > 100) )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-insert") == 0 ) {
if ( (++argno >= argc) || (inserts != NO_VALUE) )
usage( cmdname, 0 );
inserts = isnumeric( argv[argno] );
if ( (inserts < 0) || (inserts > 100) )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-delete") == 0 ) {
if ( (++argno >= argc) || (deletes != NO_VALUE) )
usage( cmdname, 0 );
deletes = isnumeric( argv[argno] );
if ( (deletes < 0) || (deletes > 100) )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-xact") == 0 ) {
if ( (++argno >= argc) || ( num_xacts != NO_VALUE) ||
(rampdtime != NO_VALUE ) || (ramputime != NO_VALUE) ||
(duration != NO_VALUE ) )
usage( cmdname, 0 );
num_xacts = isnumericL( argv[argno] );
if ( num_xacts <= 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-sec") == 0 ) {
if ( (++argno >= argc) || ( duration != NO_VALUE) ||
(num_xacts != NO_VALUE ) )
usage( cmdname, 0 );
duration = isnumeric( argv[argno] );
if ( duration <= 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-ramp") == 0 ) {
if ( (++argno >= argc) || ( ramputime != NO_VALUE) ||
( rampdtime != NO_VALUE) || (num_xacts != NO_VALUE ) )
usage( cmdname, 0 );
ramputime = isnumeric( argv[argno] );
if ( ramputime < 0 )
usage( cmdname, 0 );
rampdtime = ramputime;
}
else
if ( strcmp(argv[argno], "-rampu") == 0 ) {
if ( (++argno >= argc) || ( ramputime != NO_VALUE) ||
(num_xacts != NO_VALUE ) )
usage( cmdname, 0 );
ramputime = isnumeric( argv[argno] );
if ( ramputime < 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-rampd") == 0 ) {
if ( (++argno >= argc) || ( rampdtime != NO_VALUE) ||
(num_xacts != NO_VALUE ) )
usage( cmdname, 0 );
rampdtime = isnumeric( argv[argno] );
if ( rampdtime < 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-ops") == 0 ) {
if ( (++argno >= argc) || (opsperxact != NO_VALUE) )
usage( cmdname, 0 );
opsperxact = isnumeric( argv[argno] );
if ( opsperxact < 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-key") == 0 ) {
if ( (++argno >= argc) || (key_cnt != NO_VALUE) )
usage( cmdname, 0 );
key_cnt = isnumeric( argv[argno] );
if ( key_cnt < MIN_KEY )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-range") == 0 ) {
if ( rangeFlag != NO_VALUE )
usage( cmdname, 0 );
rangeFlag = 1;
}
else
if ( strcmp(argv[argno], "-nodbexec") == 0 ) {
if ( nodbexec != NO_VALUE )
usage( cmdname, 0 );
nodbexec = 1;
}
else
if ( strcmp(argv[argno], "-iso") == 0 ) {
if ( (++argno >= argc) || (isolevel != NO_VALUE) )
usage( cmdname, 0 );
isolevel = isnumeric( argv[argno] );
if ( (isolevel < 0) || (isolevel > 1) )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-seed") == 0 ) {
if ( (++argno >= argc) || rand_seed )
usage( cmdname, 0 );
rand_seed = (unsigned int)isnumeric( argv[argno] );
if ( rand_seed == 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-throttle") == 0 ) {
if ( (++argno >= argc) || (throttle != NO_VALUE) )
usage( cmdname, 0 );
throttle = isnumeric( argv[argno] );
if ( throttle <= 0 )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-v") == 0 ) {
if ( (++argno >= argc) || (verbose != NO_VALUE) )
usage( cmdname, 0 );
verbose = isnumeric( argv[argno] );
if ( (verbose < VERBOSE_FIRST) || (verbose > VERBOSE_LAST) )
usage( cmdname, 0 );
}
else
if ( strcmp(argv[argno], "-build") == 0 ) {
if ( (buildOnly != NO_VALUE) || (noBuild != NO_VALUE) )
usage( cmdname, 0 );
buildOnly = 1;
}
else
if ( strcmp(argv[argno], "-nobuild") == 0 ) {
if ( (buildOnly != NO_VALUE) || (noBuild != NO_VALUE) )
usage( cmdname, 0 );
noBuild = 1;
}
else
if ( strcmp(argv[argno], "-insertmod") == 0 ) {
if ( (++argno >= argc) || (insert_mod != NO_VALUE) ) {
usage( cmdname, 0 );
}
insert_mod = isnumeric( argv[argno] );
if ( insert_mod <= 0 ) {
fprintf( stderr, "Value for '-insertmod' must be > 0.\n");
return 0;
}
}
#ifdef WIN32
else
if ( strcmp(argv[argno], "-procid") == 0 ) {
if ( (++argno >= argc) || (procId != NO_VALUE) ) {
usage( cmdname, 0 );
}
procId = isnumeric( argv[argno] );
if ( procId <= 0 ) {
fprintf( stderr, "Value for '-procid' must be > 0.\n");
return 0;
}
}
#endif /* WIN32 */
#if defined(SCALEOUT)
else
if ( strcmp(argv[argno], "-scaleout") == 0 ) {
if ( mode != M_CLASSIC )
usage( cmdname, 0 );
mode = M_SCALEOUT;
#if defined(ROUTINGAPI)
if ( ((argno+1) < argc) && (strcmp(argv[argno+1],"local") == 0) ) {
mode = M_SCALEOUT_LOCAL;
argno += 1;
}
#if defined(ROUTINGAPI_ALL)
else
if ( ((argno+1) < argc) && (strncmp(argv[argno+1],"routing", 7) == 0) ) {
mode = M_SCALEOUT_ROUTING;
p = argv[argno+1]+strlen("routing");
if ( (*p != '\0') && (*p != '/') )
usage( cmdname, 0 );
if ( *p++ == '/' )
{
if ( *p == '\0' )
usage( cmdname, 0 );
if ( strlen( p ) >= CONN_STR_LEN )
usage( cmdname, 0 );
srvdsn = p;
}
argno += 1;
}
#endif /* ROUTINGAPI_ALL */
#endif /* ROUTINGAPI */
}
#endif /* SCALEOUT */
else
if ( strcmp(argv[argno], "-connstr") == 0 ) {
if ( (++argno >= argc) || (connstr_opt != NULL) || (dsn[0] != '\0') )
usage( cmdname, 0 );
connstr_opt = strdup( argv[argno] );
}
else {
if ( (connstr_opt != NULL) || (dsn[0] != '\0') )
usage( cmdname, 0 );
if ( (strlen(argv[argno])+1) > sizeof(dsn) )
usage( cmdname, 0 );
strcpy( dsn, argv[argno] );
}
argno += 1;
}
/* Check if we have a DSN which is really a connection string */
if ( dsn[0] )
{
if ( (strchr(dsn,';') != NULL) || (strncasecmp(dsn, "DSN=", 4) == 0) )
{
connstr_opt = strdup( dsn );
dsn[0] = '\0';
}
}
/* Assign defaults and computed values as required */
if ( duration != NO_VALUE ) {
if ( ramputime == NO_VALUE )
ramputime = DFLT_RAMPTIME;
if ( rampdtime == NO_VALUE )
rampdtime = DFLT_RAMPTIME;
num_xacts = 0;
}
else {
if ( ramputime != NO_VALUE )
usage( cmdname, 0 );
if ( rampdtime != NO_VALUE )
usage( cmdname, 0 );
ramputime = rampdtime = 0;
if ( num_xacts == NO_VALUE )
num_xacts = DFLT_XACT;
duration = 0;
}
if ( rand_seed == 0 )
rand_seed = DFLT_SEED;
if ( num_processes == NO_VALUE )
num_processes = DFLT_PROC;
if ( reads == NO_VALUE )
reads = DFLT_READS;
if ( inserts == NO_VALUE )
inserts = DFLT_INSERTS;
if ( deletes == NO_VALUE )
deletes = DFLT_DELETES;
if ( opsperxact == NO_VALUE )
opsperxact = DFLT_OPS;
if ( key_cnt == NO_VALUE )
key_cnt = DFLT_KEY;
if ( isolevel == NO_VALUE )
isolevel = DFLT_ISO;
if ( verbose == NO_VALUE )
verbose = VERBOSE_DFLT;
if ( rangeFlag == NO_VALUE )
rangeFlag = DFLT_RANGE;
if ( nodbexec == NO_VALUE )
nodbexec = DFLT_NODBEXEC;
if ( throttle == NO_VALUE )
throttle = DFLT_THROTTLE;
if ( buildOnly == NO_VALUE )
buildOnly = DFLT_BUILDONLY;
if ( noBuild == NO_VALUE )
noBuild = DFLT_NOBUILD;
if ( insert_mod == NO_VALUE )
insert_mod = DFLT_INSERT_MOD;
if ( procId == NO_VALUE )
procId = DFLT_PROCID;
if (num_processes != 1)
insert_mod = num_processes;
/* Various checks on inputs */
#if defined(SCALEOUT) && defined(ROUTINGAPI) && defined(ROUTINGAPI_ALL)
if ( mode == M_SCALEOUT_ROUTING )
{
if ( opsperxact > 1 )
{
err_msg0("Cannot use -ops > 1 with -scaleout routing.\n");
return 0;
}
if ( (reads < 100) && (opsperxact == 0) )
{
err_msg0("Cannot use -ops = 0 with -scaleout routing and reads < 100.\n");
return 0;
}
}
#endif /* SCALEOUT && ROUTINGAPI && ROUTINGAPI_ALL */