-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathGridSample.h
2555 lines (2381 loc) · 60.1 KB
/
GridSample.h
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, 2018, 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
*/
/************************************************************************
* Main header file for GridSample sample program
************************************************************************/
#if !defined(_GRIDSAMPLE_H)
#define _GRIDSAMPLE_H
/************************************************************************
* Include files
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
#include <signal.h>
#include <math.h>
#if ! defined(WIN32)
#include <sys/time.h>
#include <termios.h>
#include <unistd.h>
#endif
/* Set ODBC API version before including timesten.h */
/* Default is ODBC 3.5 */
#if defined(USEODBC25)
#define ODBCVER 0x0250 // ODBC 2.5
#else
#define ODBCVER 0x0350 // ODBC 3.5
#endif
#include "timesten.h"
/************************************************************************
* Constants
*/
/*
* Boolean values
*/
#define false 0
#define true 1
/*
* Default DSN
*/
#define DIRECT_DSN "sampledb"
#define CLIENT_DSN "sampledbCS"
#ifdef TTCLIENTSERVER
#define DFLT_DSN CLIENT_DSN
#else
#define DFLT_DSN DIRECT_DSN
#endif
/*
* Connection related things
*/
#define DFLT_UID "appuser"
#define DFLT_PWD NULL
#define ATTR_DSN "DSN"
#define ATTR_UID "UID"
#define ATTR_PWD "PWD"
#define ATTR_CONN_NAME "ConnectionName"
#define DFLT_CONN_NAME "GridSample"
/*
* Grid retries and failover retries
*/
#define DFLT_RETRY_LIMIT 30 // max retries for transient errors
#define DFLT_RETRY_DELAY 0 // retry delay (ms) for transient errors
#define DFLT_FAILOVER_LIMIT 100 // max retries for failover errors
#define DFLT_FAILOVER_DELAY 25 // retry delay (ms) for failover errors
/*
* Transaction names for internal 'transactions'.
*/
#define TXN_UPDGRIDINFO_NAME "UpdateGridInfo"
#define TXN_GETCOUNTS_NAME "GetCounts"
#define TXN_CLEARHISTORY_NAME "ClearHistory"
#define TXN_AUTHORIZE_NAME "Authorize"
#define TXN_QUERY_NAME "Query"
#define TXN_CHARGE_NAME "Charge"
#define TXN_TOPUP_NAME "Topup"
#define TXN_PURGE_NAME "Purge"
/*
* Transaction types - numeric constants matching transaction names.
*/
#define TXN_INVALID 0
#define TXN_UPDGRIDINFO 1
#define TXN_GETCOUNTS 2
#define TXN_CLEARHISTORY 3
#define TXN_AUTHORIZE 4
#define TXN_QUERY 5
#define TXN_CHARGE 6
#define TXN_TOPUP 7
#define TXN_PURGE 8
/*
* Default workload mix - transaction percentages. These can be overridden
* via the -txnmix command line parameter.
*/
#define DFLT_PCT_AUTHORIZE 70
#define DFLT_PCT_QUERY 5
#define DFLT_PCT_CHARGE 15
#define DFLT_PCT_TOPUP 5
#define DFLT_PCT_PURGE 5
/*
* Other defaults
*/
#define DFLT_PROGNAME "GridSample"
#define DFLT_PURGE_AGE 30 // age (seconds) for TRANSACTIONS rows to
// be a candidate to purge
#define DFLT_TOPUP_VALUE 10.0
#define MIN_CHARGE_VALUE 0.1
#define MAX_CHARGE_VALUE 1.0
/*
* Command line options
*/
#define OPT_HELP "-help"
#define OPT_DSN "-dsn"
#define OPT_UID "-uid"
#define OPT_PWD "-pwd"
#define OPT_NOCLEANUP "-nocleanup"
#define OPT_NUMTXN "-numtxn"
#define OPT_TXNMIX "-txnmix"
#define OPT_DURATION "-duration"
#define OPT_VERBOSE "-verbose"
#define OPT_SILENT "-silent"
#define OPT_LOG "-log"
#define OPT_DEBUG "-debug"
#if defined(SPECIAL_FEATURES)
#define OPT_COMMITROTXN "-commitrotxn"
#endif // SPECIAL_FEATURES
/*
* Various lengths.
*/
#define MAX_LEN_DSN 30
#define MAX_LEN_UID 30
#define MAX_LEN_PWD 30
#define MAX_LEN_CONNNAME 30
#define MAX_LEN_CONNSTR 256
#define MAX_MSG_LEN 1024
/*
* Verbosity levels and reporting intervals
*/
#define VB_SILENT 0
#define VB_NORMAL 1
#define VB_VERBOSE 2
#define VB_MIN_RPT_INTERVAL 10
#define VB_DFLT_RPT_INTERVAL 30
/************************************************************************
* Code macros.
*/
/*
* Link an item on a doubly linked list.
*
* NOTE: Error checking is limited; mis-use at your peril.
*/
#define LIST_LINK(l,e) if ((l != NULL) && (e != NULL)) \
{ \
if (l->first == NULL) \
{ \
l->first = l->last = e; \
e->next = e->prev = NULL; \
} \
else \
{ \
e->next = NULL; \
e->prev = l->last; \
l->last = l->last->next = e; \
} \
l->numentries++; \
}
/*
* Unlink an item from a doubly linked list.
*
* NOTE: Error checking is limited; mis-use at your peril.
*/
#define LIST_UNLINK(l,e) if ((l != NULL) && (l->first != NULL) && \
(e != NULL)) \
{ \
if (l->last == l->first) \
{ \
e->next = e->prev = NULL; \
l->first = l->last = NULL; \
} \
else \
if (e == l->first) \
{ \
l->first = l->first->next; \
if ( l->first != NULL ) \
l->first->prev = NULL; \
e->next = e->prev = NULL; \
} \
else \
if (e == l->last) \
{ \
l->last = l->last->prev; \
if ( l->last != NULL ) \
l->last->next = NULL; \
e->next = e->prev = NULL; \
} \
else \
{ \
e->prev->next = e->next; \
e->next->prev = e->prev; \
e->next = e->prev = NULL; \
} \
l->numentries--; \
}
/************************************************************************
* Error codes and messages.
*/
/*
* Exit codes
*/
#define EXIT_SUCCESS 0 // all good
#define EXIT_PARAM 1 // parameter error
#define EXIT_HELP 2 // user requested help on command line
#define EXIT_INTERRUPT 3 // execution interrupted
#define EXIT_ERROR 4 // an execution error occurred
/*
* Error codes and related things.
*/
#define SUCCESS 0 // no error
// Internal errors
#define ERR_HELP 1 // help requested
#define ERR_PARAM_INTERNAL 2 // internal error - bad parameter passed
#define ERR_STATE_INTERNAL 3 // internal error - state mismatch
#define ERR_TYPE_MISMATCH_INTERNAL 4 // internal error - data type mismatch
#define ERR_NOMEM 5 // out of memory
// Other errors
#define ERR_PARAM 6 // parameter error (command line)
#define ERR_SIGNAL 7 // failed to setup signal handlers
#define ERR_USER 8 // not currently used
#define ERR_DATA 9 // data error
// ODBC error classifications
#define ERR_ODBC_NO_DATA 10 // no data found
#define ERR_ODBC_NOINFO 11 // no additional info available
#define ERR_ODBC_NORMAL 12 // includes warnings
#define ERR_ODBC_RETRYABLE 13 // retryable error
#define ERR_ODBC_FAILOVER 14 // failover error
/*
* Error messages for the above error codes.
*/
#define ERRM_UNKNOWN "* unnkown error *"
#define ERRM_NO_ERROR "* no error *"
#define ERRM_HELP "* help requested *"
#define ERRM_PARAM_INTERNAL "internal error - invalid parameter"
#define ERRM_STATE_INTERNAL "internal error - invalid state"
#define ERRM_TYPE_MISMATCH_INTERNAL "internal error - data type mismatch"
#define ERRM_NOMEM "internal error - out of memory"
#define ERRM_PARAM "parameter error"
#define ERRM_SIGNAL "failed to install signal handlers"
#define ERRM_USER "user defined error"
#define ERRM_DATA "data error"
#define ERRM_ODBC_NO_DATA "ODBC error - no data returned"
#define ERRM_ODBC_NOINFO "ODBC error - no additional info"
#define ERRM_ODBC_NORMAL "ODBC error"
#define ERRM_ODBC_RETRYABLE "ODBC error - retryable"
#define ERRM_ODBC_FAILOVER "ODBC error - failover"
/*
* Other messages
*/
#define MSG_INTERRUPT "*** Interrupt"
#define MSG_TXN_LIMIT "Transaction count limit reached"
#define MSG_TIME_LIMIT "Run time limit reached"
#define MSG_WKL_STARTED "Workload started"
#define MSG_WKL_ENDED "Workload ended"
/*
* TimesTen error related things. Used for identifying and classifying
* retryable errors.
*/
#define TT_ERR_SQLSTATE_NULL ""
#define TT_ERR_SQLSTATE_RETRY "TT005"
#define TT_ERR_SQLSTATE_GENERAL "S1000"
#define TT_ERR_NATIVE_NONE 0
#define TT_ERR_NATIVE_DEADLOCK 6002
#define TT_ERR_NATIVE_LOCKTIMEOUT 6003
#define TT_ERR_NATIVE_FAILOVER 47137
/************************************************************************
* Structures and typedefs
*/
/*
* Typedefs
*/
#if ! defined(WIN32)
typedef int boolean;
#endif
typedef struct s_odbcerr odbcerr_t; // an ODBC error/warning
typedef struct s_odbcerrlist odbcerrlist_t; // list of ODBC errors
typedef struct s_parambinding parambinding_t; // ODBC parameter
typedef struct s_paramlist paramlist_t; // list of ODBC parameters
typedef struct s_colbinding colbinding_t; // ODBC column
typedef struct s_collist collist_t; // list of ODBC columns
typedef struct s_sqlstmt sqlstmt_t; // a SQL statement
typedef struct s_sqlstmtlist sqlstmtlist_t; // list of SQL statements
typedef struct s_dbconnection dbconnection_t; // a database connection
typedef struct s_apptxn apptxn_t; // generic app transaction
typedef struct s_apptxnlist apptxnlist_t; // list of generix txns
typedef struct s_txnUpdateGridInfo txnUpdateGridInfo_t; // txn to get grid
// info
typedef struct s_txnGetCounts txnGetCounts_t; // txn to get data
// counts
typedef struct s_txnClearHistory txnClearHistory_t; // txn to truncate
// TRANSACTIONS table
typedef struct s_txnPurge txnPurge_t; // workload Purge txn
typedef struct s_txnQuery txnQuery_t; // workload Query txn
typedef struct s_txnAuthorize txnAuthorize_t; // workload Authorize txn
typedef struct s_txnCharge txnCharge_t; // workload Charge txn
typedef struct s_txnTopup txnTopup_t; // workload Topup txn
typedef struct s_context context_t; // app context
/*
* ODBC error/warning structures
*/
#define LEN_SQLSTATE 5
struct s_odbcerr // represents a single ODBC error
{
odbcerr_t * next;
odbcerr_t * prev;
char sqlstate[LEN_SQLSTATE+1];
char * error_msg;
int native_error;
int retry_delay; // ms
}; // s_odbcerr
struct s_odbcerrlist // a list of ODBC errors
{
odbcerr_t * first;
odbcerr_t * last;
int numentries;
}; // s_odbcerrlist
/*
* Parameter binding structures
*/
struct s_parambinding // represents a bound parameter
{
parambinding_t * next;
parambinding_t * prev;
sqlstmt_t * stmt;
SQLSMALLINT paramno;
SQLSMALLINT InputOutputType;
SQLSMALLINT ValueType;
SQLSMALLINT ParameterType;
SQLULEN ColumnSize;
SQLSMALLINT DecimalDigits;
SQLPOINTER ParameterValuePtr;
SQLLEN BufferLength;
SQLLEN StrLen_or_IndPtr;
}; // s_parambinding
struct s_paramlist // a list of bound parameters
{
parambinding_t * first;
parambinding_t * last;
int numentries;
}; // s_paramlist
/*
* Column binding structures
*/
struct s_colbinding // represents a bound column
{
colbinding_t * next;
colbinding_t * prev;
sqlstmt_t * stmt;
SQLSMALLINT colno;
SQLSMALLINT TargetType;
SQLPOINTER TargetValuePtr;
SQLLEN BufferLength;
SQLLEN StrLen_or_Ind;
}; // s_colbinding
struct s_collist // a list of bound columns
{
colbinding_t * first;
colbinding_t * last;
int numentries;
}; // s_collist
/*
* SQL statement structures
*/
struct s_sqlstmt // represents a SQL statement
{
sqlstmt_t * next;
sqlstmt_t * prev;
dbconnection_t * conn; // associated database connection
SQLHANDLE hStmt; // ODBC statement handle
char const * sqltext; // text of SQL statement
paramlist_t * params; // list of ODBC parameters (input)
collist_t * cols; // list of columns (result set)
odbcerrlist_t * errors; // associated errors
}; // s_sqlstmt
struct s_sqlstmtlist // a list of SQL statements
{
sqlstmt_t * first;
sqlstmt_t * last;
int numentries;
}; // s_sqlstmtlist
/*
* Database Connection
*/
struct s_dbconnection
{
SQLHANDLE hEnv; // ODBC environment handle (per connection)
SQLHANDLE hDbc; // ODBC connection handle
sqlstmtlist_t * stmts; // associated statements
odbcerrlist_t * errors; // associated errors
char * dsn; // DSN value
char * uid; // UID value
char * pwd; // PWD value
char * cname; // ConnectionName value
boolean connected; // is it connected?
}; // s_dbconnection
/*
* Application Transaction (generic). Structures to hold things common to all
* application transactions.
*/
typedef int (*FPinit_t)(void *); // init function
typedef int (*FPexecute_t)(void *); // execute function
typedef int (*FPfetch_t)(void *); // fetch function
typedef int (*FPclose_t)(void *); // cursor close function
typedef int (*FProwcount_t)(void *,long *); // get rowcount function
typedef void (*FPcleanup_t)(void *); // cleanup function
struct s_apptxn // a generic transaction
{
apptxn_t * next;
apptxn_t * prev;
context_t * ctxt; // associated context
sqlstmtlist_t * stmts; // associated statements
int txntype; // txn type code
void * parent; // parent (specific) transaction
FPinit_t init; // init function, never NULl
FPexecute_t execute; // execute function, never NULl
FPfetch_t fetch; // fetch function, can be NULL
FPclose_t close; // cursor close function, can be NULL
FProwcount_t rowcount; // get rowcount function, can be NULL
FPcleanup_t cleanup; // cleanup function, never NULl
}; // s_apptxn
struct s_apptxnlist // a list of generic transactions
{
apptxn_t * first;
apptxn_t * last;
int numentries;
}; // s_apptxnlist
/*
* Structure representing the UpdateGridInfo transaction.
*
* Retrieves information about the connected database (is it a grid database
* or a regular database) and if it is a grid database, the database element
* that the application is currently connected to.
*/
struct s_txnUpdateGridInfo
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * isGridStmt; // SQL statement to determine if DB
// is a grid DB
sqlstmt_t * localElementStmt; // SQL statement to determine the
// connected element's ID
sqlstmt_t * cursor; // current cursor
boolean griddb; // is DB a grid DB?
int localelement; // id of connected element
}; // s_txnUpdateGridInfo
/*
* Structure representing the GetCounts transaction.
*
* Retries the rowcount and minimum/maximum primary key values for the
* CUSTOMERS and ACCOUNTS tables. These values are used by the workload code
* when generating random customer and account IDs .
*/
struct s_txnGetCounts
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * stmtCountCustomers; // SQL statement to get CUSTOMER counts
sqlstmt_t * stmtCountAccounts; // SQL statement to get ACCOUNT counts
sqlstmt_t * cursor; // current cursor
long minCustID; // min customer ID
long maxCustID; // max customer ID
long numCustomers; // number of customers
long minAccountID; // min account ID
long maxAccountID; // max account ID
long numAccounts; // number of accounts
}; // s_txnGetCounts
/*
* Structure representing the ClearHistory transaction.
*
* Clears down the TRANSACTIONS table using TRUNCATE TABLE.
*/
struct s_txnClearHistory
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * truncateStmt; // SQL statement for TRUNCATE
}; // s_txnClearHistory
/*
* Structure representing the Purge transaction.
*
* Removes 'old' rows from the TRANSACTIONS table to avoid unbounded growth.
*/
struct s_txnPurge
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * purgeStmt; // SQL statement for purge operation
int purgeAge; // age (seconds) used to determine 'old' rows
}; // s_txnPurge
/*
* Structure representing the Query transaction.
*
* Retrieves information about a customer and all of their accounts.
*/
struct s_txnQuery
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * queryStmt; // SQL statment for query
long custID; // the customer ID for the query
sqlstmt_t * cursor; // the cursor
// row data; populated on each successful fetch
boolean rdvalid; // is the data valid?
long cust_id; // customer ID
char * last_name; // last name
char * member_since; // member_since; date
long account_id; // account ID
char * phone; // phone number
short status; // status
double current_balance; // current account balance
}; // s_txnQuery
/*
* Structure representing the Authorize transaction.
*
* Checks that an account exists with the correct attributes and returns the
* associated customer ID and phone number.
*/
struct s_txnAuthorize
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * authorizeStmt; // SQL statement for the query
long accountID; // the account ID for the query
sqlstmt_t * cursor; // the cursor
// row data; populated on each successful fetch
boolean rdvalid; // is the data valid?
long cust_id; // customer ID
char * phone; // phone number
}; // s_txnAuthorize
/*
* Structure representing the Charge transaction.
*
* Depletes a specific account's balance by a specified amount. Logs a
* 'jurnal' record in the TRANSACTIONS table.
*/
struct s_txnCharge
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * selectStmt; // SQL statement for the query
sqlstmt_t * updateStmt; // SQL statement for the balance update
sqlstmt_t * insertStmt; // SQL statement for the TRANSACTIONS insert
sqlstmt_t * cursor; // the cursor
long accountID; // target account ID
double adjustAmount; // amount to adjust balance by
}; // s_txnCharge
/*
* Structure representing the Topup transaction.
*
* Replenishes a specified account by a specified amount.
*/
struct s_txnTopup
{
apptxn_t * txn; // associated generic txn
sqlstmt_t * selectStmt; // SQL statement for the query
sqlstmt_t * updateStmt; // SQL statement for the balance update
sqlstmt_t * insertStmt; // SQL statement for the TRANSACTIONS insert
sqlstmt_t * cursor; // the cursor
long accountID; // target account ID
double adjustAmount; // amount to adjust balance by
}; // s_txnTopup
/*
* Application Context.
*
* All 'global' variables gathered together in a single structure for ease
* of management and access.
*/
struct s_context
{
// Values from program arguments
char const * progName; // program name
char const * dbDSN; // DSN value
char const * dbUID; // UID value
char const * dbPWD; // PWD value
boolean doCleanup; // clear down TRANSACTIONS at start?
boolean commitReadTxn; // commit read-only transactions?
long runNumTxn; // number of transactions to execute
long runDuration; // time to run for (seconds)
int vbLevel; // verbosity level
int vbInterval; // verbosity reporting interval (seconds)
char const * logPath; // path of log file
boolean debugMode; // is debug mode enabled?
int pctAuthorize; // % of Authorize txns in workload
int pctQuery; // % of Query txns in workload
int pctCharge; // % of Charge txns in workload
int pctTopUp; // % of Topup txns in workload
int pctPurge; // % of Purge txns in workload
// Other 'globals'
int purgeAge; // mnimum age for 'old' records (seconds)
char * connName; // connection name
boolean limitExecution; // apply runtime limits?
int retryLimit; // maximum retries for retryable errors
int failoverLimit; // maximum retries for failovers
FILE * logOut; // log file
long startTime; // start time (ms)
long stopTime; // stop time (ms)
// totals for statistics
long totalRetries;
long totalCSFailovers;
long totalTxnExecuted;
long totalTxnAuthorize;
long totalTxnQuery;
long totalTxnCharge;
long totalTxnTopup;
long totalTxnPurge;
long totalAccountUpdates;
long totalTransactionInserts;
long totalTransactionDeletes;
// interval statistics
long intvlRetries;
long intvlCSFailovers;
long intvlTxnExecuted;
long intvlTxnAuthorize;
long intvlTxnQuery;
long intvlTxnCharge;
long intvlTxnTopup;
long intvlTxnPurge;
long lastReportTime ;
// DB related stuff
dbconnection_t * dbconn; // database connection
odbcerrlist_t * errors; // last error stack
long minCustID; // min and max customer IDs
long maxCustID;
long numCustomers; // number of customers
long minAccountID; // min and max account IDs
long maxAccountID;
long numAccounts; // number of accounts
boolean isGrid; // a grid DB?
int prevElementID; // the previously connected element
int currElementID; // the current connected element
int rtCount; // current retry count
int foCount; // current failover count
// Transactions
apptxnlist_t * apptxns; // list of generic transactions
txnUpdateGridInfo_t * ugitxn; // UpdateGridInfo txn
txnGetCounts_t * gctxn; // GetCounts txn
txnClearHistory_t * chtxn; // ClearHistory txn
txnPurge_t * ptxn; // Purge txn
txnQuery_t * qtxn; // Query txn
txnAuthorize_t * atxn; // Authorize txn
txnCharge_t * ctxn; // Charge txn
txnTopup_t * ttxn; // Topup ntxn
// Error handling
int errNumber; // last error code
// Message buffer
char msgBuff[MAX_MSG_LEN+1]; // general usage message buffer
}; // s_context
/************************************************************************
* Functions
*************************************************************************/
/*************************************************************************
* Utility Functions
*/
#if defined(WIN32)
/*
* The 'strsep' function for platforms that don't have it.
*/
char *
strsep(
char **stringp,
const char *delim
);
#endif /* WIN32 */
/*
* Sleep for a specified number of milliseconds.
*
* INPUTS:
* ms - number of ms to sleep for
*
* OUTPUTS: None
*
* RETURNS: Nothing
*/
void
sleepMs(
unsigned int ms
);
/*
* Have we received a signal?
*
* INPUTS: None
*
* OUTPUTS: None
*
* RETURNS:
* Number of signal last received or 0.
*/
int
signalReceived(
void
);
/*
* Install signal handlers for SIGHUP, SIGINT and SIGTERM.
*
* INPUTS: None
*
* OUTPUTS: None
*
* RETURNS:
* Success or error code.
*/
int
installSignalHandlers(
void
);
/*
* Global cleanup and termination function.
*
* INPUTS:
* ctxt - pointer to a pointer to a context_t
exitcode - process exit code to use for exit()
*
* OUTPUTS: None
*
* RETURNS: Nothing, does not return.
*/
void
cleanup(
context_t * * ctxt,
int exitcode
);
/*
* Check if a string might be a simple positive integer value.
*
* INPUTS:
* s - the string
*
* OUTPUTS: Nothing
*
* RETURNS:
* true or false
*/
boolean
isSimpleInt(
char const * s
);
/*
* Check if a string might be a simple positive long long value.
*
* INPUTS:
* s - the string
*
* OUTPUTS: Nothing
*
* RETURNS:
* true or false
*/
boolean
isSimpleLong(
char const * s
);
/*
* Get current clock time with millisecond precision.
*
* INPUTS: None
*
* OUTPUTS: None
*
* RETURNS:
* Current time since the epoch expressed as milliseconds.
*/
long
getTimeMS(
void
);
/*
* Generate a timestamp string for messages.
*
* INPUTS: None
*
* OUTPUTS: None
*
* RETURNS:
* A pointer to a static buffer containing the timestamp string in the
* format YYYY-MM-DD hh:mm:ss.fff.
*/
char *
getTS(
void
);
/*
* Free a 'context_t' and everything it contains.
*
* INPUTS:
* ctxt - a pointer to a pointer to a context_t
*
* OUTPUTS: Nothing
*
* RETURNS: Nothing
*/
void
freeContext(
context_t ** ctxt
);
/*
* Allocate and initialise a 'context_t'
*
* INPUTS:
* nctxt - a pointer to a pointer to a context_t
*
* OUTPUTS:
* nctxt set to point to the allocated and initialized context_t
*
* RETURNS:
* Success or an error code.
*/
int
allocContext(
context_t ** ctxt
);
/*
* Translate an error code into an error message.
*
* INPUTS:
* errorCode - a valid error code
* ctxt - a pointer to a valid context_t
*
* OUTPUTS: None
*
* RETURNS:
* A pointer to the error message textt that corresponds to the
* error code. The data pointed to is read only and statically allocated.
*/
char const *
errorMessage(
int errorCode,
context_t * ctxt
);
/*
* Check if an error and associated error stack represents a retryable error.
*
* INPUTS:
* err - error code
* errstack - ODBC error stack
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is retryable (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a retryable error, false otherwise.
*/
boolean
isRetryable(
int err,
odbcerrlist_t * errstack,
int * delay
);
/*
* Check if an error and associated error stack represents a connection
* failover error (client/server mode only).
*
* INPUTS:
* err - error code
* errstack - ODBC error stack
*
* OUTPUTS:
* delay - pointer to an integer to receive the retry delay value if this
* error is a failover (can be NULL if the value is not required)
*
* RETURNS:
* True if the error is a failover error, false otherwise.
*/
boolean
isFailover(
int err,
odbcerrlist_t * errstack,
int * delay
);
/*
* Display (and log) an error message. Errors are always displayed and
* also are always logged if logging or debug is enabled. If an ODBC error
* list is passed, display the list of errors.
*
* INPUTS:
* ctxt - a pointer to a valid context_t
* msg - pointer to a message to display. If NULL is passed,
* uses ctxt->msgBuff.
* odbcerrs - an ODBC error list or NULL
*
* OUTPUTS: None
*
* RETURNS: Nothing
*/
void
displayError(
context_t const * ctxt,
char const * msg,
odbcerrlist_t const * odbcerrs
);
/*
* Log a message (if logging is enabled). Nothing is displayed.
*
* INPUTS:
* ctxt - a pointer to a valid context_t
* msg - pointer to a message to log. If NULL is passed,
* uses ctxt->msgBuff.
*
* OUTPUTS: None
*
* RETURNS: Nothing
*/
void
logMessage(
context_t const * ctxt,
char const * msg
);
/*
* Display and/or log a message. Messages are only displayed if
* silent mode is not in effect. Messages are always logged if logging
* or debug is in effect.
*
* INPUTS:
* ctxt - a pointer to a valid context_t
* msg - pointer to a message to display/log. If NULL is passed,
* uses ctxt->msgBuff.
*
* OUTPUTS: None
*